为什么C打印两次?

时间:2017-03-30 17:11:01

标签: c

我确定这很简单,但有人可以告诉我为什么下面的代码会打印两次用户提示吗?提前谢谢。

#include <stdio.h>
int main(void) {
    char task = 't';
    while (task != 'q') {
        printf("What do you want to do? (quit with 'q'): ");
        scanf("%c", &task);
    }
}

输出:

What do you want to do? (quit with 'q'): a
What do you want to do? (quit with 'q'): What do you want to do? (quit with 'q'): b
What do you want to do? (quit with 'q'): What do you want to do? (quit with 'q'): c
What do you want to do? (quit with 'q'): What do you want to do? (quit with 'q'): q

它退出&#39; q&#39;喜欢它。谢谢你的帮助。

0 个答案:

没有答案