问题描述
- C语言文件读取遇到的问题
-
原题是:输入一个正整数n,然后读取n个正整数,最后再读取一个正整数m,统计有多少整数小于m。代码如下,
int main()
{
FILE *fin,*fout;
fin = fopen("data.in","rb");
fout = fopen("data.out","wb");
int n,x,m,i,count = 0;
fscanf(fin,"d",&n);
printf("%dn",n);
i = 1L;
while (feof (fin) == 0){
fseek(fin,i,0);
fscanf(fin,"d",&x);
if (x < m){
count++;
}
i++;
}
printf("%dn",count);
fclose(fin);
fclose(fout);
return 0;
}
但是会陷入死循环,求大神解答
时间: 2024-10-29 05:34:59