Recap: Task Manager
Combine malloc/free, enums, and typedef
Mission: The Technical Intervention Queue
A short-circuit fire has knocked out half the computer room. The shift technician needs a dynamic task tracker to manage the repair jobs. Each task is heap-allocated, has a status, and must be freed when the queue is cleared.
- Define typedef enum { TODO, IN_PROGRESS, DONE } Status;
- Define typedef struct { char title[100]; Status status; } Task;
- Write Task *create_task(const char *title): allocates a Task with malloc, copies the title, sets the status to TODO, returns the pointer
- Write void update_status(Task *t, Status s): updates the task's status
- Write const char *status_name(Status s): returns "TODO", "IN_PROGRESS", or "DONE" (use a switch)
- Write void print_task(Task *t): prints the task as "[STATUS] Title"
- Read from input a count n of tasks, followed by n lines, each with a title (a single word) and a status code (0 = TODO, 1 = IN_PROGRESS, 2 = DONE). Create each task and update it to the status read
- Print all the tasks, in order, then free the memory
Example
Input
3
Check_tape 2
Fix_teletype 1
Recalibrate_reader 0
Output
[DONE] Check_tape
[IN_PROGRESS] Fix_teletype
[TODO] Recalibrate_reader
Example
Input
2
Replace_fuse 2
Clean_fans 0
Output
[DONE] Replace_fuse
[TODO] Clean_fans