What is the difference between these two programs. I read in a book that the first method is better but isn't there larger use of memory?
First
#include<stdio.h>
#include<string.h>
int main()
{
char line[100];
int value;
printf("Enter the Number to be doubled : ");
fgets(line,sizeof(line),stdin);
sscanf(line, "%d", &value);
printf("The double of the number is %d \n",2*value);
return(0);
}
Second
#include<stdio.h>
#include<string.h>
int main()
{
int value;
printf("Enter the value\n");
scanf("%d",&value);
printf("The double of the number is %d",2*value);
}
Question
LeviS LoVEr
What is the difference between these two programs. I read in a book that the first method is better but isn't there larger use of memory?
First
#include<stdio.h> #include<string.h> int main() { char line[100]; int value; printf("Enter the Number to be doubled : "); fgets(line,sizeof(line),stdin); sscanf(line, "%d", &value); printf("The double of the number is %d \n",2*value); return(0); }Second
#include<stdio.h> #include<string.h> int main() { int value; printf("Enter the value\n"); scanf("%d",&value); printf("The double of the number is %d",2*value); }Link to comment
Share on other sites
8 answers to this question
Recommended Posts