← C Programming learning path
C Programming · Module 10 of 10

Files and projects

Read and write files, and organise programs into multiple files.

📖 Key ideas

  1. FILE *f = fopen("data.txt", "r"); opens a file ("w" write, "a" append).
  2. fprintf, fscanf, fgets and fputs read and write text.
  3. Always check fopen for NULL and fclose when done.
  4. Split big programs into .c files and .h headers.
  5. 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