while (scanf ("%d", &n)!=eof)

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.