Windows console input, which is opened in text mode by default, cannot be read to the CR when entered, even if the text mode is not changed, because Windows has converted CRLF to a single LF.
If Freopen ("CON", "RB", stdin); You can read the CR
Fgets will absorb line breaks, but line breaks are also written to the string
If not string, scanf ("%d", &d); Gets () best. vs2015 Delete gets, with gets_s can.
First: Fgets reads a string with ' \ n '. That is, in the case of no more than the second argument, Fgets reads the characters from the third argument (the file pointer, the input stream) continuously. until ' \ n' is encountered and ' \ n ' is removed from the input stream .
Second: The gets function does not detect the number of characters that are read in. Just continuously read characters from the standard input stream (keyboard) until ' \ n ' is encountered. Unlike fgets, the Get function will take ' \ n ' out of the input stream, but only remove it and discard it. is not saved in the target string (the code above is both str).
Finally: The scanf function does not detect the number of characters that are read in. Just continuously read characters from the standard input stream (keyboard) until you encounter a " white space character ." Unlike Fgets/gets, scanf does not remove " whitespace " from the input stream.
Always keep in mind that the ' \ R ' is a whitespace character, and the scanf function will not read into it. But the fgets and gets function reads it!
http://blog.csdn.net/lanceleng/article/details/8730192
scanf
SCANF will leave the line break in the input buffer, and%s will leave
Most of the conversion specifiers skip leading whitespace including newlines and does not %c
.
In a formatted string, most directives will ignore whitespace (isspace), except%c
Preceded by a space, the leading whitespace is ignored, including line breaks.
while (scanf ("%c", &c)!=-1)
printf ("%c", c);
Pressing CTRL + Z does not end
The following sequence can end
CTRL + Z, CR
Ctrl+z,cr
Ctrl+d
Windows C Input Note