这是我的主要功能:
int main(int argc, char **argv)
{
LoadFile();
Node *temp;
char *key;
switch (GetUserInput())
{
case 1:
temp = malloc(sizeof(Node));
printf("\nEnter the key of the new node: ");
scanf("%s", temp->key);
printf("\nEnter the value of the new node: ");
scanf("%s", temp->value);
AddNode(temp);
free(temp);
break;
case 2:
key = malloc(sizeof(char *));
printf("Enter the key of the node you want to delete: ");
scanf("%s", key);
DeleteNode(key);
free(key);
break;
case 3:
PrintAll();
break;
case 4:
SaveFile();
break;
case 5:
return 0;
break;
default:
printf("\nWrong choice!\n");
break;
}
return 0;
}
唯一的问题是,在任何 case 语句中断后,程序就会退出。我明白为什么,但我不知道如何解决它。即使在案例陈述之后,我也希望程序每次都重复自己。我只想说:
main(argc, argv);
在每个 break 语句之前?