File Handling

FILE HANDLING:
Whenever some amount of data has to be stored permanently in a storage media like a floppy or disk, we need to organize it in a file. The file can contain data sequential form or in a table form i.e. rows and columns.
 

C provides many functions for handling data in single character as well as multiple character formats. A few operations to be carried out on files are :
1.  Naming a file
2.  Opening a file
3.  Reading data from a file
4.  Writing data from a file
5.  Closing a file.
 
Various file handling functions:

Function name —— Operation
1) fopen()
—Creates a new file for use/ Opens an existing file for use
2) fclose()
—Closes a file which has been opened for use.
3) getc()
—Reads a character from file.
4) putc()
—Write a character to a file.
5) fprintf()
—Write a set of data values to a file.
6) fscanf()
—Read a set of data values from a file.
Various file accessing modes:
1.    “ r ” [ read only mode ] : it specifies that the file can only be read from.
2.    “ w ” [write only mode] : it specifies that the file can only be written into.
3.    “ a ” [append mode] : it specifies that the file opened is in write mode and the data added shall not be over written but shall get appended at the end of file.

0 comments:

Post a Comment