当用户输入单词“ quit”时如何退出循环?

时间:2019-11-10 18:24:19

标签: c loops

所以我有以下代码:

static int counter = 1;
while (1){
        printf("%d> ", counter);
        char input[69];
        fgets(input, 69, stdin);
        printf("%s", input);
        if (strcmp(input, "quit") == 0){
            break;
        }
        counter++;
    }

,我希望当用户输入“退出”时循环中断。但是上面的代码并没有破坏 用户输入“退出”时循环播放。以下是我的输出:

1> test1
test1
2> test2
test2
3> quit
quit
4> 

如何做到这一点,以便在用户键入“退出”时循环中断?

0 个答案:

没有答案