/    /  End Of File

End Of File

 

  • EOF is a macro defined as int and has a negative value. It is normally returned by the functions that carry out read operations to indicate either an error or the end of the input. The input of a terminal never really ends (unless the device is disconnected), but it is useful to enter multiple “files” in a terminal, so a string of keys is reserved to indicate the end of the input.
  • Ctrl+Z is the key of the DOS to finish or finish the input values.
  • Ctrl+D is the key in UNIX to stop entry values.

 

Example Program:

 

To write a file and read a file.

 

#include<stdio.h>
main( ){
FILE *fp;
char ch;
fp=fopen("DATA1.txt","w");
printf("Enter the Text:\n");
printf("Use Ctrl+z to stop entry \n");
while((scanf("%c",&ch))!=EOF)
fprintf(fp, "%c",ch);
fclose(fp);
printf("\n");
fp=fopen("DATA1.txt","r");
printf("Entered Text is:\n");
while((fscanf(fp,"%c",&ch))!=EOF)
printf("%c",ch);
fclose(fp);
}

 

Output:

 

End Of File