← C Programming learning pathC Programming · Module 10 of 10
Files and projects
Read and write files, and organise programs into multiple files.
📖 Key ideas
- FILE *f = fopen("data.txt", "r"); opens a file ("w" write, "a" append).
- fprintf, fscanf, fgets and fputs read and write text.
- Always check fopen for NULL and fclose when done.
- Split big programs into .c files and .h headers.
- Typical C projects: student records, bank system, games, embedded firmware.
💡 Real-life example: A FILE pointer is a library card: you check out a file (fopen), read or write, then return it (fclose).
fopenOpens a file
fcloseCloses a file
"a" modeAppends to the end of a file
Header fileDeclarations shared between .c files