COMPLETE EXPLANATION OF
gets()
FUNCTION in C
--------------------------------------------------------------------------------
Example CODE1:
INPUT: Welcome to coding
{
char str[100];
scanf("%s",str);
printf("%s",str);
}
(Expected OUTPUT: Welcome to coding)
OUTPUT: Welcome
*************************************************************************
1) The scanf() funtion stops reading when a new line or a white space
is detected.
2) So to print a string with spaces in it, we have to use a
function called => gets()
*************************************************************************
SYNTAX => gets(variable name);
The gets function stops getting input only when a new line is entered
* IMPORTANT: must be initialised before scanning *
*************************************************************************
Example CODE1(corrected version):
INPUT: Welcome to coding
{
char str[100];
gets(str);
the compiler to continue taking input even if it detects
blank or white spaces.
scanf("%s",str);
printf("%s",str);
}
(Expected OUTPUT: Welcome to coding)
OUTPUT: Welcome to coding