【发布时间】:2015-07-30 00:38:05
【问题描述】:
我希望在用户决定以 (Ctrl+d) (即 EOF)结束之前询问用户“他们想写多少圈”?
额外的问题:如果我写一个字母,例如“k”,它会发出垃圾邮件。我该如何改变?
#include <stdio.h>
int main ()
{
int i;
int x;
printf("\nHow many circles do you want to write?\n");
scanf("%d", &x);
while(x != EOF)
{
for (i = 1; i <= x; i = i + 1)
{
putchar('o');
}
printf("\nHow many circles do you want to write?"
"(to end program click ctrl+d at the same time!))\n");
scanf("%d", &x);
}
printf("\n\n Bye! \n\n");
return 0;
}
【问题讨论】:
标签: c while-loop printf scanf eof