【发布时间】:2012-07-17 02:14:31
【问题描述】:
我的代码:
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp;
int id,q,p,r,a;
fp = fopen("g-ip.txt","r");
while(EOF!=fscanf(fp,"%d\t%d\t%d\t\t%d\t\t%d",&id,&q,&p,&r,&a))
printf("%d %d %d %d %d\n",id,q,p,r,a);
fclose(fp);
return 0;
}
格式字符串之所以如此,是因为我的 g-ip.txt 文件具有以相同格式写入的值。在执行代码时,它给了我错误的输出,即无限次打印的垃圾值。我应该使用数组来读取中的值吗?但我不想使用它。
【问题讨论】:
-
稍微偏离主题:在 fscanf 中指定空白字符并不新鲜。
-
数据文件是否写在同一台电脑上?
-
@steffen:是的,数据已写入同一台计算机
-
好的。排除了字节序问题
-
我刚刚尝试了你的确切代码,它对我有用...我用
gcc test.c编译
标签: c linux file-io ubuntu-10.04