#include<stdio.h>
#include<string.h>
void main()
{
FILE *fp; //Create a file pointer *fp
char ch;
fp=fopen("D:/data.txt","r"); //Open D:\data.txt file as read-only
if(fp==NULL)
printf("can not open!\n"); //If the fp pointer is empty, that is, the file is empty, the output can not open
else{
//Read characters: fscanf(fp,"%c",&ch), ch=fgetc(fp);
fscanf(fp,"%c",&ch); //read characters
while(!feof(fp)){ //feof() This function is used to determine whether the pointer has reached the end of the file, that is, if it does not reach the end of the loop
putchar(ch); //output
fscanf(fp,"%c",&ch); //read characters again
}
fclose(fp); //Close the file
}
printf("\n");
}
Source File:
running result: