There are several messages about switch statements in while loops, with the exception of the fact that none of them executed in C, at least from what I saw. C ++ can create logical expressions that I know of, but not in C. I have a while loop containing a switch control. However, when I write break instructions on my switch, it goes back to the beginning of the loop and makes my program work forever. Ignore the functions that I use because they work exactly. I just need to clarify how I handled the nest. Thank!
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);
}
}
source
share