C File Handling : I/O Operations

In computer system a file represents a sequence of bytes, regardless of it being a text file or a binary file. Files are created for permanent storage of data. In other words a file is a place on  the disk where a group of related data is stored.

The C language supports a number of functions that have the ability to perform basic file operations, which include :
  • Naming a file
  • Opening a file
  • Reading data from a file
  • Writing data from a file
  • Closing an opened file

C Functions for File Handling :

The functions available in C library for handling file I/O are :

Function name Description
fopen() Create a new file to use or open an existing file.
fclose() Closes a file which has been opened.
fread() Read from a binary file.
fwrite() Write to a binary file.
fseek() Sets the position to a desired point in a file.
ftell() Gives the current position in the file (In terms of bytes from start).
rewind() Sets the position to the beginning of the file.
getc() Reads a character from a file.
putc() Writes a character to a file.
getw() Reads an integer from a file.
putw() Writes an integer to a file.
fgets() Reads strings from a file.
fputs() Writes strings to a file.
fprintf() Writes a set of data to a file.
fscanf() Reads a set of data from a file.
feof() Checks the file position if the end of file is reached or not.

Note : Click on function names on the above table for more detailed explanation.

Next Topic :