What is the difference between GETS();AND SCANF();

Answers were Sorted based on User's Feedback



What is the difference between GETS();AND SCANF();..

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

What is the difference between GETS();AND SCANF();..

Answer / vignesh1988i

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

What is the difference between GETS();AND SCANF();..

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

What is the difference between GETS();AND SCANF();..

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

Post New Answer

More C Interview Questions

Difference between data structure and data base.

7 Answers   CTS, Value Labs, Zoho,


C program to perform stack operation using singly linked list

3 Answers  


What is the meaning of typedef struct in c?

0 Answers  


What Is The Difference Between Null And Void Pointer?

0 Answers   TCS,


int n=1; while(1) { switch(n) { case 1:printf("a"); n++; continue; case 2:printf("b"); n++; continue; default : printf("c"); break; } break; }

1 Answers  






What is else if ladder?

0 Answers  


what is diffrence between string and character array?

1 Answers  


Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?

0 Answers  


write a program in 'c' to find the value of p[i+1]^n.p,i,n are arguments of a macro and n is a integer

1 Answers  


Is register a keyword in c?

0 Answers  


How can I access an I o board directly?

0 Answers  


What is data structure in c programming?

0 Answers  


Categories