Input/Output Function Family
The family name can be used for all streams only for stdin and stdout
Getchar Character Input fgetc, GETC getchar
Putchar output fputc, putc putchar
Gets text line Input fgets gets
Puts text line output fputs puts
Scanf format input fscanf scanf
Printf format and output fprintf printf
Note:
Both fgetc and fputc are real functions, but GETC, putc, getchar, and putchar are macros defined by the # define command,
Therefore, parameters with side effects cannot be used when GETC, putc, getchar, and putchar are called.
The usage of fgets is as follows:
Char * fgets (char * string, int N, file * stream );
Fgets () is used to read characters from the file referred to by the parameter stream and coexist to the memory space referred to by the parameter string until a line break occurs, the end of the file is read, or n-1 characters have been read, finally, null is added as the string. If you read a line break or an EOF when the number of characters (n-1 characters) is not fully read ),The read operation ends. The string to be read last contains the line break, and another character is null. If the string cannot store the entire row, the next fgets call will start to read from the next character of stream without data loss.
FputsWrite a string to the specified file (the string end mark '\ 0' is not automatically written ')
GetsReads a string from the stdin stream until it receives a linefeed or EOF, and stores the read results in the character array pointed to by the STR pointer. Line breaks are not used to read strings,The read linefeed is converted to a null value and ends the string.
The gets function is insecure and does not limit the size of the input buffer, which may easily cause overflow. Therefore, do not use gets as much as possible.