TaleemBay
Study
UniversitiesScholarshipsFeesDates
TaleemBay

Empowering students with Next-Gen tools for a brighter future. Your one-stop destination for education in Pakistan.

Quick Links

  • Universities
  • Study Center
  • Past Papers
  • Date Sheets
  • Results

Support

  • About Us
  • Contact
  • Privacy Policy
  • Terms of Service
  • Advertise

Contact Us

  • Arfa Software Technology Park,
    Ferozepur Road, Lahore
  • +92 300 1234567
  • hello@taleembay.com

© 2026 TaleemBay. All rights reserved.

Designed with ❤️ for Pakistan

Home
Unis
Study

Study Center

Overview
9th Class10th Class11th Class12th Class

Resources

Past PapersDate Sheets

Need Notes?

AI-powered search for instant answers.

Chapter 14
computer-science • intermediate 12th

Chapter 14: File Handling in C

Comprehensive notes for Chapter 14 File Handling in C. Covers streams, text vs binary files, file opening modes, and I/O functions like fopen, fclose, fprintf, fscanf.

Streams

Definition: A logical interface to a file is known as a stream. It is a flow of data.

  • Text Stream: Sequence of characters. Character translations (like newline) may occur. No one-to-one correspondence with external device bytes.
  • Binary Stream: Sequence of bytes. No translation occurs. One-to-one correspondence with external device bytes. More efficient than text streams.

File Access Methods

  • Sequential Access: Data is accessed in the same sequence as it is stored. Simple but slow for large files.
  • Random Access: Data can be accessed directly without reading preceding data. Fast and efficient for searching.

File Operations

Opening a File (fopen): Associates a file with a stream. Syntax: FILE *fp = fopen("filename", "mode");

Closing a File (fclose): Disconnects the file from the program. Syntax: fclose(fp);

Modes:

  • "r": Read only (file must exist).
  • "w": Write only (creates new or overwrites existing).
  • "a": Append (adds to end, creates if not exists).
  • "r+": Read/Write (file must exist).
  • "w+": Read/Write (overwrites/creates).
  • "a+": Read/Append.

I/O Functions

  • Character I/O: fgetc() (read char), fputc() (write char).
  • String I/O: fgets() (read string), fputs() (write string).
  • Formatted I/O: fscanf() (read formatted data), fprintf() (write formatted data).

Key Concepts

  • EOF (End of File): Special marker indicating the end of data in a file.
  • File Pointer: A pointer of type FILE that points to the information required to manage a file.