这是我的主要功能:
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 语句中断后,程序都会退出。我明白原因,但不知道如何解决。我希望程序每次都重复自己,即使在 case 语句之后也是如此。我只想说:
main(argc, argv);
在每个break语句之前?
最佳答案
稍等一下(1) { }
例如
while(1)
{
//switch... etc down to the close of the switch
}
关于c - 迭代C 中的main 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2726200/