Step 5 of 7
Appending
Mode "a" opens a file for appending: it's created if missing, and every write goes to the end, keeping what was there. That's exactly what log files need.
Other modes you'll meet:
| Mode | Meaning |
|---|---|
"r+" |
read and write an existing file |
"rb", "wb" |
binary mode: no newline translation (matters on Windows) |
Your turn: write int append_line(const char *path, const char *line) that appends line plus a newline. Return 0 on success and -1 if the file can't be opened.
Previous: Loading records Next: Safe formatting with snprintf