循环用户输入

时间:2015-10-10 01:37:00

标签: c fflush

我正在尝试设置一个用户可以继续输入字符串的循环。不知道我哪里出错了(我是C编程的新手)

这是我写的代码:

#include <stdio.h>

void main() {
    int repeat;
    char str[30];
    do
    {
        printf("Enter a string:");
        fgets(str, 30, stdin);
        printf("Do you want to continue\n");
        fflush(stdin);
        scanf_s("%d", &repeat);
    } while (repeat==1);
}

这是我得到的输出:

Enter a string:hello
Do you want to continue
1
Enter a string:Do you want to continue
1
Enter a string:Do you want to continue

提前致谢。

0 个答案:

没有答案
相关问题