c - 迭代C 中的main 函数?

标签 c iteration switch-statement main-method

这是我的主要功能:

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/

相关文章:

c++ - 为什么行>列时数组的内存占用更大

javascript - JSTL 和 JavaScript

C#:开关与工厂类中的方法重载

switch-statement - 可选 bool 值元组上的 Swift switch 语句

c - 如何在不对变量本身进行任何更改的情况下检查 char 指针变量的第一个字符

c - 了解C语言中函数指针的typedef

c - 我需要帮助在二十一点、C 中洗牌整数

c++ - 非常基本的 std::vector 迭代

Ruby:如何使用 .each 遍历数组?

arrays - 如何为数组进行切换?