What is the difference between GETS();AND SCANF();
Answers were Sorted based on User's Feedback
Answer / bharath
gets() read the string values which allows white spaces
also. whereas, scanf() doesn't allow.
| Is This Answer Correct ? | 230 Yes | 19 No |
the main difference between gets() and scanf() function is that while getting any input as a stream of characters or as a string using scanf() , the end termination character is a blank space or an enter key for scanf() , so upto blank space it will be saving it in the memory...... SHORTLY it ignores the characters comin after and with blank spaces........
in gets() , it allows with the blank spaces and the termination condition is a enter key (\n) ,
but a inside gets() function , surely they would have used scanf() function , but the difference is that the input inside gets() would go character by character , so only gets() can allow with the blank spaces...........
thank u
| Is This Answer Correct ? | 103 Yes | 47 No |
Answer / niraj kumar
Main difference between '%s' and 'gets' is:
%s ends taking input when it encounter whitespace, new line(
) or EOF.
gets takes whitespace and stops taking input when it encounters new line(
) or EOF.
| Is This Answer Correct ? | 14 Yes | 9 No |
Answer / rejith vr
We can use scanf() instead of gets()
Syntax : gets(str);
||
||
scanf("%[^
]s",str);
it will accept multiple words in a string
| Is This Answer Correct ? | 5 Yes | 23 No |
What is call by value in c?
main() { int a,b; printf("%d,%d",scanf("%d%d",&a,&b)); } => do u mean above program's output... =>output will be:2,whatever you enter value for b. =>because scanf is a library fn which will return how many arguements it processes, and second value you are right mr.Satya but i found my self unable to understand that for the first time scanf returns the no of successful matches but how for the second time it returns the value of 'b'.while a function should return the same 'r' value every time.
What is the use of header?
what is the output? #define fun(a,b,t) (g ##t=(a),(a)=(b),(b)=g##t) float gfloat; main() { float a=1.12,b=3.14; fun (a,b,float); printf("na=%4.2f,b=%4.2f",a,b); } A)Error in Defining Macro B)a=1.12,b=3.14 C)a=3.14,b=1.12 D)None of the Above
3 Answers Accenture, Infosys, Wipro,
Explain what is the use of a semicolon (;) at the end of every program statement?
What is the difference between union and structure in c?
Why shouldn’t I start variable names with underscores?
Why enum is used in c?
What is your favorite subject?
1 Answers Ericsson, Invendis, Tech Mahindra,
What is typedef struct in c?
Explain what is the difference between functions getch() and getche()?
What is the difference b/w main() in C language and main() in C++.