I. Preface
1. line I/O can be executed in two ways-unformatted or formatted. Both methods are used to operate strings.
2. unformatted I/O: simple reading or writing of strings, while formatted I/O performs conversion between numbers and internal and external representations of other variables.
II. I/O not formatted
1. I/O function declaration not formatted
1> char * fgets (char * buffer, int buffer_size, file * stream );
2> char * gets (char * buffer );
3> int fputs (char const * buffer, file * stream );
4> int puts (char const * buffer );
1. The gets and puts functions are used to operate strings rather than individual characters.
2. fgets reads characters from the specified stream and copies them to the buffer. When it reads a linefeed and stores it in the buffer, it will not read it again. It also stops reading if the number of stored characters in the buffer reaches the buffer_size-1.
1> in any case, a NUL byte is added to the end of the data stored in the buffer to make it a string.
2> if it reaches the end of the file before any characters are read, the buffer zone is not modified. The fgets function returns a null pointer. Otherwise, fgets returns its first parameter (pointer to the buffer ). This return value is usually used only to check whether the object has reached the end of the file.
3. The buffer passed to fputs must contain a string whose characters are written to the stream. This string ends with NUL bytes, so this function does not have a buffer length parameter. This string is written word by word: if it does not contain a line break, it will not be written as a line break. If it contains several linefeeds, all linefeeds will be written. Therefore, when fgets reads an entire row at a time, fputs can either write a part of a row at a time or write a whole row at a time, or even write several rows at a time. If an error occurs during writing, fputs returns the constant value EOF. Otherwise, it returns a non-negative value.
4. The gets and puts functions are almost the same as fgets and fputs. One of the main differences between them is:
1> when gets reads a row of input, it does not store the end line break in the buffer. When puts writes a string, it adds a linefeed to the output after the string is written.
2> another difference lies in gets, which has no buffer length parameter. Therefore, gets cannot determine the buffer length.