[英]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.