There are several postings concerning switch statements within while loops, except for the fact that none of them are done in C, at least from what I've seen. C++ can create boolean expressions, which I'm aware of, but not in C. I have a while loop that contains a switch control. However, when I write break statements within my switch, it goes back to the beginning of the loop and makes my program run forever. Ignore the functions I use, for they work for sure. I just need some clarification on my handling of the nesting. Thanks!
Here is my main.c:
while(1)
{
printf("0) Exit\n1) List Tasks\n2) Add Task\n");
printf("3)Delete Task\n4) Add Task From File\n");
printf("What would you like to do?\n");
fgets(buf1, 50, stdin);
p = atoi(buf1);
switch(p)
{
case 0:
break;
case 1:
printTaskList(pTaskList);
break;
case 2:
printf("Enter task name: ");
fgets(buf2,100,stdin);
printf("Enter task priority: ");
fgets(buf3,100,stdin);
printf("Enter task start date: ");
fgets(buf4,50,stdin);
pTask = makeTask(buf2,buf4,buf3);
addTaskToEnd(pTaskList,pTask);
break;
case 3:
printTaskList(pTaskList);
printf("What task would you like to delete? ");
fgets(buf6,50,stdin);
taskNum = atoi(buf6);
removeTask(pTaskList,taskNum);
break;
case 4:
printf("Enter the filename ");
fgets(buf7,50,stdin);
break;
default:
printf("ERROR: %d: Incorrect menu option\n", p);
}
}