For the C language's question about "input contains multiple lines of data, please handle to end of the file", multiple lines

Source: Internet
Author: User

For the C language's question about "input contains multiple lines of data, please handle to end of the file", multiple lines

Today, when I was in the ACM competition, I encountered the following requirement in the input format: the input contains multiple rows of data. Please process it until the end of the file. The logic of the question is very simple, and the main function code is easy to implement, but the question does not "clearly" indicate how the input data in the console ends, such as: # And double carriage return. I tried to use the clock_t variable to control the program running time, but the "Compilation error" was displayed on the evaluation platform ". After careful analysis, the author gets the answer: "input contains multiple rows of data, please process until the end of the file" means that when you input enough data, you can use "Ctrl + Z" to exit the console, that is, "processing file ends". The reason is: Ctrl + Z will make the scanf () function return-1, so when dealing with this type of problem, you can use "while (scanf (" % d ", & a, & B )! = EOF) {function.

Related Article

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.