I'm working on a tasklist program to brush up on my C before I take a class. I have two structs, task and tasklist.
Here is the task struct:
typedef struct task
{
char name[100];
bool completed; /* bool is described as an enum in an included header file */
date due_date; /* date is a described as a struct in an included header file */
} task;
I have the following working functions:
- List item
- init_tasklist(tasklist): initialize tasklist variables
- add_task(): add task to the tasklist
- delete_task(): delete the given task from the tasklist
- print_tasklist(): print out the tasklist similar to a normal todo list with a checkbox, name and due date for each item
- delete_tasklist(): delete the given tasklist
- print_task(): print out the details of a given task
My question has to do with which variables to have as parameters to functions and what to return.
I would like to use this tasklist for a cli interface and then change it to a GUI, so I would like to make that an easy switch.
At first, I had add_task() malloc()-ing a new task and returning a pointer to that task, and then delete_tasklist() recursively went through and free()-ed the memory as it deleted the tasklist. I got this approach from my experience with OOP and Java.
What's the best way to design this in C?
Should the add_task() function take a task struct to add to the list or perhaps just the variables that should be in the task and have the add_task() function initialize it?
Should I write a get_task() function that returns the pointer to a task with the given name for functions like print_task() and delete_task(), which would take a task pointer, or should those take char pointers and find the task themselves?
Any guidance on how to design the I/O of these functions would be very helpful.