当将文件拖到数组中时,缺乏了解
我正在执行CS50(第4周实验室4卷),我必须将标题从输入WAV文件复制到输出文件(44个首字节)。
首先,我创建了数组uint8_t header [header_size];
。然后,我使用了fread
。但是为什么正确的解决方案为:fread(header,header_size,1,input);
而不是:fread(header,sizeof(uint8_t),header_size,header_size,input); ?
这是否意味着所有标头将在单个元素中的header
数组中立即复制(这会导致错误,因为由于其类型,元素必须具有1个字节。 uint8_t
)?现在,编译器是否一次读取许多字节为每个元素仅1个字节的数组时,如何处理情况?
谢谢你!
I'm doing CS50 (Week 4 Lab 4 Volume) and I have to copy a header from an input WAV file to output file (the 44 first bytes).
To start, I created the array uint8_t header[HEADER_SIZE];
. Then, I used fread
. But why the right solution is : fread(header, HEADER_SIZE, 1, input);
and not something like : fread(header, sizeof(uint8_t), HEADER_SIZE, input);
?
Don't it mean that all the header will be copied at once in the header
array in a single element (which will lead to an error since an element must have 1 byte due to its type uint8_t
)? Does the compiler now how to handle the situation when reading at once many bytes into an array with only 1 byte per element?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论