1

在一个相当大的命令行应用程序的中间,它一直在工作。进行了一些更改以处理大于我可以缓冲的文件并遇到来自fread.

DebugLog(@"Reading %d samples of a total %d samples of size %d, leaving %d samples remaining", numSamplesToRead, numSamplesInFile, sizeof(short) * channels * scaleFactor, numSamplesRemainingInFile);
DebugLog(@"Position in file is %d", ftell(in));
items = fread(dataBuffer, sizeof(short) * channels * scaleFactor, numSamplesToRead, in);
DebugLog(@"%d samples read", items);
DebugLog(@"Position in file is %d", ftell(in));

这将产生以下输出:

<main:(604)> Reading 29278208 samples of a total 115202048 samples of size 8, leaving 85923840 samples remaining
<main:(605)> Position in file is 512
<main:(607)> 448 samples read
<main:(608)> Position in file is 58560512

(有问题的文件大小为 225008K。)

那么我如何才能读取每个 8 字节的 448 个样本并从位置 512 移动到位置 58560512?为什么没有读取请求的数据量?

4

1 回答 1

2

的返回值fread()应与nitems参数相同(numItemsToRead在您的情况下为 )。items和不同的事实numItemsToRead表明读取出现问题,但是由于文件指针已经超过已读取的内容,因此您的缓冲区可能有问题?

您应该检查errno和/或ferror()查看是否有任何相关信息。

于 2012-06-29T06:44:38.653 回答