File end function (feof)

Source: Internet
Author: User

Function feof (FP // file pointer) is used to test whether the internal position pointer of the file pointed to by FP points to the end of the file. If the file ends, the value of the feof (FP) function is 1 (true). If it does not end, the value of the feof (FP) function is 0 (false ), the feof function can determine the end of binary and text files.

Example:

Copy the data of a local file to another file (a.txt is an existing file)

# Include <stdio. h> int main () {file * fpin, * fpout; char ch; If (fpin = fopen ("D: \ a.txt", "RT ")) = NULL) // open the source file {printf ("cannot open a.txt \ n");} If (fpout = fopen ("D: \ B .txt ", "WT") = NULL) // open the target file {printf ("cannot open B .txt \ n");} CH = fgetc (fpin ); // read the first character of the original file printf ("directly output the content of file a \ n"); While (! Feof (fpin) // determines whether the source file ends {putchar (CH); fputc (CH, fpout); CH = fgetc (fpin);} printf ("\ n "); fclose (fpin); fclose (fpout); printf ("\ n Copy file a to file B and output file B content \ n "); if (fpout = fopen ("D: \ B .txt", "RT") = NULL) {printf ("cannot open B .txt \ n ");} ch = fgetc (fpout); While (! Feof (fpout) {putchar (CH); CH = fgetc (fpout);} fclose (fpout); printf ("\ n"); Return 0 ;}

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.