如何在使用while loop scanf!= EOF后使用scanf

时间:2014-09-25 09:26:41

标签: c

我必须将.in文件输入我的program.gcc ./" file" < file.in
因为有多个输入我必须使用While循环EOF,但是 因为我不能再扫描一次。 这是我的程序的模拟版本。谢谢

#include <stdio.h>

int main() {
    int arr[100];
    int num;
    int count = 0;
    while( scanf("%d", &arr[count]) != EOF ) {
        count++;
    }
    printf("%d\n", arr[0]);
    scanf("%d", &num);
    printf("%d\n", num);
}

1 个答案:

答案 0 :(得分:1)

试试这个

freopen("con:", "r", stdin);//this for windows. "/dev/tty" for *nix ?
scanf("%d", &num);