Program output source file itself (interview questions)

Source: Internet
Author: User

Yesterday, I encountered a problem when I went to the public comment interview. The interviewer asked: please writeProgramThe program function is able to output the program file from the beginning to the end. If you can write it out in five minutes, we will commit it!

For such an interview question, I thought about it and wrote it for your reference.

Source program:

# Include <stdio. h> # include <stdlib. h> int main () {// defines the file stream pointer file * file = fopen ("Main. C "," R "); // determine whether the file stream is successfully opened before reading. If (file = NULL) {// output error message perror (" Main. C "); Return exit_failure;} int ch; // read and output while (CH = fgetc (File) cyclically ))! = EOF) {fputc (CH, stdout) ;}fclose (File); Return 0 ;}

The program running result is:

Although the program is simple, if you can write it quickly and accurately, the offer belongs to you!

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.