Item | Value |
Header file | stdio.h |
Declaration | char *gets(char *str); |
Function | reads characters from stdin. The newline character is translated into a null to terminate the string. |
Return | a null pointer on failure. |
You cannot limit the number of characters that gets() will read.
#include <stdio.h> #include <stdlib.h> int main(void) { char fname[128]; printf("Enter filename: "); gets(fname); printf("%s \n", fname); return 0; }
Enter filename: 321 321
22.22.gets | ||||
22.22.1. | gets | |||
22.22.2. | Using gets and putchar | |||
22.22.3. | gets() reads in only text |