我正在使用 fread 将文件内容读取到一个字符数组中。但我不确定为什么它没有打印在输出中。这是代码:
void getInfo(FILE* inputFile)
{
char chunk[4];
int liIndex;
for (liIndex = 0 ; liIndex < 4 ; liIndex++)
{
fread(chunk, sizeof(char), 4, inputFile);
}
printf("\n chunk %s", chunk);
}
输出什么都不打印。我哪里错了?
问候, 小黑
最佳答案
将 printf
移到循环中。实际上,您只打印最后读取的 block 。
编辑:显然,我阅读了问题,但没有阅读标题。您必须像 Thomas 所说的那样和切换到 fwrite
。
关于c - 带有二进制文件的 C 中的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2581002/