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

Question 1: You want to conduct a survey within your classroom, on the quality of canteen’s food. You ask each of your class fellows to rank the quality of food between 1 and 5 (1 representing excellent quality and 5 representing worst quality). During the survey, you make a list containing the roll# of student and the opinion given by that student. The list can be as follow Roll # Opinion 234 1 235 1 236 5 237 1 238 2 239 3 240 5 241 5 242 1 To get the results of the survey, you need to determine the frequency of each opinion value. The frequency of an opinion is determined by counting the number of students giving that opinion. For example, for the above list the frequency of opinion value 1 is 4 and frequency of opinion value 4 is 0. After getting the frequency of each opinion, you can easily judge about the quality of the food by seeing through the frequency of each opinion. You need to develop a program to calculate the results of this survey. The program inputs the opinion of 50 students and counts the frequency of each opinion. It then displays a report showing the frequency of each opinion. Sample output: Opinion Frequency Remarks 1 5 Excellent 2 10 Good 3 15 Normal 4 10 Bad 5 10 Really bad

1 Answers  


Write a c program to build a heap method using Pointer to function and pointer to structure ?

0 Answers   Wipro,


3. Program to print all possible substrings. ex: String S St Str Stri Strin String t tr tri trin tring r

3 Answers   Huawei,


1.find the second maximum in an array? 2.how do you create hash table in c? 3.what is hash collision

9 Answers   HCL, Qualcomm,


What is string constants?

0 Answers  






what is a headerfile?and what will be a program without it explain nan example?

6 Answers   Assurgent,


Write a program that an operator and two operands read from input operand operator on the implementation and results display.

0 Answers  


let's take a code struct FAQ { int a; char b; float c; double d; int a[10]; }*temp; now explain me how the memory will be allocated for the structure FAQ and what address will be in the structure pointer (temp)....................

8 Answers  


Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?

0 Answers   Infosys,


how to make program without <> in library.

1 Answers   ADITI,


the number of measuring units from a arbitrary starting point in a record area or control block to some other point a) branching b) recording pointer c) none d) offset

0 Answers  


what is disadvantage of pointer in C

13 Answers   Tech Mahindra,


Categories