{Quality Online Education Since 2009}

C Programming File Handling


C files I/O functions handles data on secondary storage device, such as a hard disk.

C can handle files as Stream-oriented data (Text) files and System oriented data (Binary) files.

Stream oriented data files The data is stored in same manner as it appears on the screen. The I/O operations like buffering, data conversions etc. take place automatically.
System oriented data files System-oriented data files are more closely associated with the OS and data stored in memory without converting into text format.

C File Operations

There are five major operations that can be performed on a file are:

Steps for Processing a File

To handling files in C, file input/output functions available in the stdio library are:

Function Uses/Purpose
fopen Opens a file.
fclose Closes a file.
getc Reads a character from a file
putc Writes a character to a file
getw Read integer
putw Write integer
fprintf Prints formatted output to a file
fscanf Reads formatted input from a file
fgets Read string of characters from file
fputs Write string of characters to file
feof Detects end-of-file marker in a file

« Previous Chapter
C Unions
Next Chapter »
C fopen