File Handling in C
📘 C
👁 28 views
📅 Dec 22, 2025
⏱ Estimated reading time: 2 min
File handling in C is used to store data permanently on secondary storage (files).
C provides file handling functions through the stdio.h library.
Types of Files
-
Text Files
-
Binary Files
File Pointer
-
A file is accessed using a FILE pointer
Opening a File
fopen() Function
File Opening Modes
| Mode | Description |
|---|---|
r | Read |
w | Write |
a | Append |
r+ | Read and write |
w+ | Write and read |
a+ | Append and read |
Closing a File
Writing to a File
Using fprintf()
Using fputc()
Reading from a File
Using fscanf()
Using fgetc()
Example Program (Write to File)
Example Program (Read from File)
feof() Function
Checks end of file.
Advantages of File Handling
-
Permanent data storage
-
Data sharing between programs
-
Large data handling
Summary
-
File handling uses
FILEpointer -
fopen()opens a file -
fclose()closes a file -
Read and write using file functions
-
Supports text and binary files
🔒 Some advanced sections are available for Registered Members
Register Now
Register Now
Share this Post
← Back to Tutorials