gets
char * gets (char * buffer ); | stdio.h |
cplusplus.com |
Get a string from stdin.
Reads characters from stdin and stores them into
buffer until
a newline (\n) or EOF character is encountered.
The ending newline character (\n) is not included in the string returned,
instead of that a null character (\0) is appended at the end of the resulting string.
There is no limit on how many characters gets may read, so it's your job to determinate the length of the buffer you will need.
Use this function to read complete lines including spaces (and any character). This function
will return everything readed before the newline character (\n).
Parameters.
Return Value.
On success, the buffer parameter is returned.
On end-of-file or error, a null pointer is returned. Use
ferror or feof
to check what happened
Example.
/* gets example */
#include <stdio.h>
main()
{
char string [256];
printf ("Insert your full address: ");
gets (string);
printf ("Your address is: %s\n",string);
return 0;
}
See also.
fputs,
fgetc,
fgets,
puts