Gets the string function read from the standard input device. Can be read indefinitely without judging the upper limit to return to the end of the read. The function's specific functions are as follows: reads a string from the stdin stream until it is accepted to a newline or EOF, and stores the result of the read in the character array pointed to by the buffer pointer. The newline character is not read as the contents of the string, and the read line break is converted to the ' \ s ' null and thus ends the string.
You should pay attention to the following features when using the Get function: You can read indefinitely without judging the upper limit, so the programmer should make sure that buffer space is large enough so that no overflow occurs while the read operation is performed. If overflow, the extra character is written to the stack, destroying the value of one or more unrelated variables. This fact causes the GET function to only apply to the toy program, in order to avoid this situation, we can use Fgets (stdin) to read the standard input to replace the get (). For backwards compatibility, gets removes line breaks, and gets does not buffer the newline character.
The Fgets function is used to read a string from a file. The Fgets function is called as follows: Fgets (STR,N,FP); here, the FP is the file pointer; Str is the starting address of the string, and n is an int type variable. function is the function of the file from the FP read into the n-1 characters into the STR as the starting address of the space, if the n-1 characters are not read, read a line break or an EOF (file end flag), the end of this read operation, the read in the string is the last to include read the newline character. So, to be exact, you can only read n-1 characters when you call the Fgets function. At the end of the read, the system will automatically add ' + ' at the end and return with STR as the function value. The prototype is Char *fgets (char *s, int n, FILE *stream);
Also note the considerations when mixing the scanf function with the gets function:
1, get in scanf before the call, this call generally do not have any problems, you can enter the normal.
2, scanf is called before get, this situation will be a problem, when the variables in the scanf, run to the Get function, do not let enter any characters, this problem occurs because the Get function received the scanf after the input return character, The solution is to use the GetChar function to receive the carriage return in the middle of scanf and get, so there is no problem.
C-language gets function, use of fgets function