Google News
logo
File handling In C Language
A file is a place on disk where group of related data are stored. C supports a number of functions that have the ability to perform basic file operations, which include: 

• Creating a new file
• Opening a file 
• Reading data from a file 
• Writing data to a file 
• Closing the file

Why files are needed ?

When the program is terminated, the entire data is lost in C programming. If you want to keep large volume of data, it is time consuming to enter the entire data. But, if file is created, this information can be accessed using few commands.

Working with file :

While working with file, you need to declare a pointer of type file. This declaration is needed for communication between file and program.

Syntax : FILE *ptr;

C provides a number of functions that helps to perform basic file operations; all these functions are available in stdio library.

Function description
fopen() create a new file or open a existing file
fclose() closes a file
getc() reads a character from a file
putc() writes a character to a file
fscanf() reads a set of data from a file
fprintf() writes a set of data to a file
getw() reads a integer from a file
putw() writes a integer to a file
fseek() set the position to desire point
ftell() gives current position in the file
rewind() set the position to the beginning point