我真的不知道如何解决这个问题,因为据我所知,它们是在两个不同的开关盒中。如果有谁能向我解释一下为什么这个问题不能解决,或者提供一种可能更有效的开关机壳的替代方案,我将非常感激。
if (StudentDB == NULL){
printf("The file does not exist. Would you like to create one?\nY/N\n");
scanf(" %c", &d);
switch (d){
case 'Y':
case 'y':
{
StudentDB = fopen ("studentdb.txt", "w");
printf("A new file has been created\n");
if (unsaved==1)
{
printf("Would you like to save your unsaved student files to this document\nY/N\n");
scanf(" %c", &e);
switch (e)
case 'Y':
case 'y':
unsaved = 0;
while (printing < student_no){
printing++;
printf("A");
fprintf(StudentDB,"%s %s\t%d\t%d %d %d/t%.2f\n",
arr_student[printing].fname, arr_student[printing].sname, arr_student[printing].UP_no, arr_student[printing].marks_1,
arr_student[printing].marks_2, arr_student[printing].marks_3, arr_student[printing].average_mark);
}
fclose(StudentDB);
printf("saved");
break;
case 'N':
case 'n':
break;
}
}
case 'N':
case 'n':
printf("Returning to menu");
delay(1);
break;
}
你漏掉了大括号,对于一条语句,你可以加或不加大括号,但对于多条语句,你一定要加大括号,如果你不加大括号,那么只有switch语句之后的那行才在switch下,下一行不在switch中。