Step 1 of 7
Write a file, read it back
fopen opens a file and gives you a FILE * handle. The second argument is the mode:
| Mode | Meaning |
|---|---|
"r" |
read; fails if the file doesn't exist |
"w" |
write; creates the file, or empties it if it exists |
"a" |
append; writes go to the end |
Then use fprintf(f, ...) exactly like printf, and always fclose(f) when you're done. Closing flushes buffered data to disk and frees the handle.
On this site, each run gets its own private, empty folder, so your program can create files freely.
Your turn: open scores.txt for writing, then for reading.