我在ansi c学习C,我有一个问题。C在输入键停止
我该如何停止从控制台读取当用户打印输入。
理想情况下,用户键入5,则该程序输出后马上进入这个
1 2 3 4 5
和
1
2
3
4
5
我有这样的代码:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
int main()
{
int vector[SIZE] = {0}, number, counter = 0,i;
while (scanf("%d", &number) != EOF && counter < SIZE){
vector[counter] = number;
counter++;
}
for (i = 0; i < counter; i++){
printf("%d\n", vector[i]);
}
return 0;
}
现在,该计划如果我输入1 2 3 4 5
,然后按ENTER,它不会停止,如果我输入1 2 3 4 5 6
它程序停止。
两件事。
我相信条件扫描,直到EOF它不是什么都不做。第二,程序因为counter < SIZE
而停止,那么在用户点击进入后该如何停止?
感谢