Click here to Skip to main content
16,004,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir! what is EOF in 'c' programming.
topic is file handling.
Posted

1 solution

EOF in any programming language is for End Of File.

So if you are trying to display the contents of file and want to stop when the file ends, you can use the condition to check EOF.

For example: -


C#
/* Program to display the contents of a file on screen */
#include <stdio.h>
void main()
{
   FILE *fopen(), *fp;
   int c;
   fp = fopen("prog.c","r");
   c = getc(fp) ;
   while (c!= EOF)
   {
        putchar(c);
        c = getc(fp);
        printf("%c", c);
   }
   fclose(fp);
   getch();
}



Hope this is helpful. Let me know if you need more help.

--
AJ
 
Share this answer
 
v3
Comments
tusharkaushik 22-Jun-11 11:33am    
thanks sir! but it 's compiled but not showing output.
ankitjoshi24 22-Jun-11 11:37am    
I have updated the solution. Check and test.

Inserted printf(c) and getch()
tusharkaushik 22-Jun-11 11:39am    
but how can i check that file is created or not?
could you please ...
what is the default location of the file created through file handling.
thanxx in advance...
tusharkaushik 22-Jun-11 11:40am    
i can't understand dude!
ankitjoshi24 22-Jun-11 11:41am    
you need to create a file separately. This program just displays the file and I put this program for you to understand how EOF works. So just open Notepad, create a file and save it in the location where your program is stored.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900