[英]fscanf not able to read the values
我正在尝试使用fscanf读取文本文件。我正在ubuntu上的OpenCV中的eclipse中工作。 以下是文本文件中的一些示例值0 5 7 0.547619047619048 1 0.0274509803921569 1 0 6 8 0.541666666666667 1 0.0313725490196078 1 0 8 10 0.533333333333333 1 0.0392156862745098 1
但是所有fscanf读取的都是数组中的零,这是代码中读取值的部分
long double testd[1000][6]
FILE* fid1=fopen("file","r");
while((fscanf(fid1,"%Lf",&b))==1)
{
printf("%Lf\n",b);
testsamplecount=testsamplecount+1;
}
for (i=0;i<testsamplecount/6;i++)
{
fscanf(fid1,"%Lf %Lf %Lf %Lf %Lf %Lf",
&testd[i][0],&testd[i][1],
&testd[i][2],&testd[i][3],
&testd[i][4],&testd[i][5]);
}
testd[i][0]
等是一个右值。 您需要的是&testd[i][0]
。
第一个循环使用文件。 尝试rewind(fid1);
在循环之间。
编辑:另外,作为一种选择,可能会比较费力,但性能要高一倍,请执行一个循环,读取直到没有更多数据为止。
我认为您不要将文件指针移动到文件的起点。 使用库fseek(fp,0,0)或尝试关闭文件,然后再次打开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.