Combine file I/O with everything you've learned! You'll write a program that saves tasks to a file, then reads them back and prints each one with a number.
YOUR TASK
Write a C program that:
Reads n task descriptions from stdin
Writes each task to a file called tasks.txt
Re-opens the file for reading and prints each task as 1. Task name
Need a hint?
Step-by-step:
1. Read n then loop reading tasks with fgets
2. Open file: FILE *f = fopen("tasks.txt", "w");
3. Write each task: fprintf(f, "%s", task);
4. Close with fclose(f);
5. Re-open for reading: f = fopen("tasks.txt", "r");
6. Read lines with fgets and print with a counter: printf("%d. %s", i, line);
Example (input: 2, Buy groceries, Call mom):
1. Buy groceries
2. Call mom
Code Editor
Ready
Output
Console
Console initialized...
Ready for Project 5: File-Based To-Do List
> Test your code with the "Check My Code" button
> When it passes, the Complete button will unlock!