For a regular array, just do this:
todolist[index] = newTodo;
However, if you need it, it can be wise to add a field to indicate if the cell is initialized or not, so you know if it contains valuable info. You could do like this:
typedef struct
{
int initialized;
char title[length];
char createdDate[length];
int completed;
} Todo;
Todo todolist[100] = {0}; // This initialization is important
And now we can du stuff like this to assign first free cell to a new Todo:
size_t i=0;
while( !todolist[i].initialized ) {
i++;
if( i >= 100 ) {
/* Handle error */
}
}
todolist[i] = newTodo;
realloc()to add elements (You will also have to keep track the number of elements by yourself in this case)todolist[index] = newTodo