man手册中的描述
NAME
gets - get a string from standard input (DEPRECATED)
SYNOPSIS
#include
char *gets(char *s);
DEscriptION
Never use this function.
gets() reads a line from stdin into the buffer pointed to by s until
either a terminating newline or EOF, which it replaces with a null
byte (' '). No check for buffer overrun is performed (see BUGS
below).
BUGS
Never use gets(). Because it is impossible to tell without knowing
the data in advance how many characters gets() will read, and because
gets() will continue to store characters past the end of the buffer,
it is extremely dangerous to use. It has been used to break computer
security. Use fgets() instead.
description:fgets是从标准输入中读取一行直到遇到n或者EOF结束并将其替换成 ,没有缓冲区溢出检查
bugs:因为不可能知道gets()将要读取多少字符,以及因为gets将继续存储超过缓冲区末端的字符,是极其危险的。
2.fgetsSYNOPSIS
#include
int fgetc(FILE *stream);
char *fgets(char *s, int size, FILE *stream);
int getc(FILE *stream);
int getchar(void);
int ungetc(int c, FILE *stream);
DEscriptION
fgetc() reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error.
getc() is equivalent to fgetc() except that it may be implemented as a macro which evaluates stream more than once.
getchar() is equivalent to getc(stdin).
fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a new‐
line is read, it is stored into the buffer. A terminating null byte (' ') is stored after the last character in the buffer.
ungetc() pushes c back to stream, cast to unsigned char, where it is available for subsequent read operations. Pushed-back characters will be returned in reverse order;
only one pushback is guaranteed.
Calls to the functions described here can be mixed with each other and with calls to other input functions from the stdio library for the same input stream.
For nonlocking counterparts, see unlocked_stdio(3).
RETURN VALUE
fgetc(), getc() and getchar() return the character read as an unsigned char cast to an int or EOF on end of file or error.
fgets() returns s on success, and NULL on error or when end of file occurs while no characters have been read.
fgets()最多从stream中读入一个小于size的字符,并将它们存储到s所指向的缓冲区中。读入在EOF或换行符之后停止。如果一个新行被读取,它被存储到缓冲区中。结束空字节(' ')存储在缓冲区的最后一个字符之后。



