Difference between scanf() and gets()

Difference between scanf() and gets()

Difference between scanf() and gets() in Tabular Form

The Key Difference between scanf() and gets() is that scanf() is used to read all types of data. While gets() is used to read-only string data.

Difference between scanf() and gets()

Comparison Chart

scanf() gets()
It is used to read all types of data. It is used to read-only string data.
It is terminated by using white space. It is terminated by entering the key or at end of the line.
It cannot read the white space between two words of a string. It is used to read complete strings with white spaces.
It requires a format specifier to read formatted data. It can read a single string at a time, It does not require a format specifier.
Syntax:

  • scanf(“list of format specifier”, list of addresses of variable);
Syntax:

  • gets(String_variable);
Example:

int x,y;
scanf("%d%d",&x,&y);

 

 

Example:

char ch[10];
gets(ch);

 

 





More Difference