I'm trying to build a small and first project of mine in C. I want to build a to-do list in list for which I'm using structures, something like
struct tasks{
int id;
char desc[150];
}task[100];
I've defined maximum no. of tasks that is 100 and description can take max 150 character.
However, while creating a new task, I'm unable to store a complete sentence even temporarily during the time program is running as after space C thinks it's done; all it takes is the first word of the sentence.
I tried different things like gets()
, getchar()
but fails to implement it while using in structure.
Can someone point me in the right direction on how I can make the create function which can take the whole sentence as input from the user and not just one word.
edit 1:
so I tried the fgets() and the program compiled correctly with no error yet not functioning correctly.
void create(){
printf("Enter task description"):
fgets(task[i].desc,150,stdin);
printf("%s\n", task[i].desc ); //to check what's going on and all i get is blank space
printf("Task successfully created.\n\n");
}
and the int id part is the second part of the program where I'd like to associate a uid to each task by default along with a time stamp.