在这段代码中,我try 使用fread()
函数从文件中读取所有数据.
问题是在数组中没有读取任何内容.
如何修复该错误?
#include <stdio.h>
void func(const char *srcFilePath)
{
FILE *pFile = fopen(srcFilePath, "r");
float daBuf[30];
if (pFile == NULL)
{
perror(srcFilePath);
} else {
while (!feof(pFile)) {
fread(daBuf, sizeof(float), 1, pFile);
}
}
for (int i = 0; i < 5; i++) {
printf(" daBuf = %f \n", daBuf[i]);
}
}
void main() {
const char inputfile[] = "/home/debian/progdir/input";
func(inputfile);
}
输入文件的值如下所示:
1.654107,
1.621582,
1.589211,
1.557358,
1.525398,
1.493311,
1.483532,
1.483766,
1.654107,