Monday, April 23, 2018

File Handling in c Reading to a file

File Handling in c Reading to a file






                                                         Need of File Handling:

The data that is generated by programs will be lost when the program is terminated. Hence for later use we need to store the information at some place and this place is FILE. 
File is a medium to store and later retrieve information.




File operations:

1.       Create
2.       Open
3.       Read
4.       Write
5.       Close
6.       Seek

Example: Reading the content of file  abc.txt

#include<stdio.h>

#include<conio.h>

void main()

{

FILE *fp;

char ch;

fp=fopen(�abc.txt�,�r�);

while(1)

{

                Ch=fgetc(fp);


                If(ch==EOF)

                {

                                break;

}

printf("%c",ch);

}

fclose(fp);

}



Know about writing to a file in c




visit link download