The return value of the scanf is determined by the following arguments
scanf ("%d%d", &a, &b);
If both A and B are read successfully, then the return value of scanf is 2
If only A is read successfully, the return value is 1
If both A and B are not read successfully, the return value is 0
If you encounter an error or encounter end of file, the return value is EOF.
And the return value is type int.
Verify:
Sign = scanf ("%d%d", &a,&b);
printf ("%d%d\n", a,b);
printf ("%d\n", sign);
But when the "a X" is entered, the output sign is 0.
When does the output EOF? In Stdio.h, the macro is defined as-1.
According to the instructions, the SCANF function may return EOF only if the first argument is null (a null pointer), otherwise the number of parameters (>=0) for which the successfully formatted and assigned values are returned.
End of File, where the acronym for the computer is usually EOF, where the operating system determines that the data source has no more data to read.
int C;
while ((c = GetChar ())!= EOF) {
Putchar (c);
}
However, the standard input is not the same as the file, you cannot know in advance the length of the input, you must manually enter a character, indicating arrival EOF. In Linux, at the beginning of a new line, press ctrl-d to represent EOF (if you press ctrl-d in the middle of a line, it means the buffer of the output "standard input", so you must press two times ctrl-d); In Windows, Ctrl-z represents EOF. (By the way, Linux presses ctrl-z, means that the process is interrupted, suspended in the background, with FG command can be back to the foreground; Press CTRL-C to terminate the process.) So, what if you really want to type in ctrl-d. You must press CTRL-V first, then you can enter the ctrl-d, the system does not think that this is an EOF signal. Ctrl-v says "literal" to interpret the next input, if you want to enter the ctrl-v by "literal meaning", enter two consecutive times on the line.
EOF means end of file .... You press Ctrl+d to try.
This article turns from: http://blog.sina.com.cn/s/blog_5a2bbc860101c8f2.html