CHAPTER 22 / 26

C File Handling

Learn the basics of reading from and writing to files.

01 — Syntax

FILE *file = fopen("file.txt", "r");

02 — Example

#include <stdio.h>

int main() {
    FILE *file = fopen("aifa.txt", "w");

    if (file != NULL) {
        fprintf(file, "Hello AIFA");
        fclose(file);
        printf("File operation completed.");
    }

    return 0;
}

03 — Important Points

04 — Common Mistakes

05 — Real-World Use

File handling is used for persistent data, configuration and reports.

06 — Practice

Create a small program that demonstrates the main idea of C File Handling.

▶ Try It Yourself← PreviousNext →All Chapters