当将文件拖到数组中时,缺乏了解

发布于 2025-02-11 05:35:21 字数 445 浏览 1 评论 0原文

我正在执行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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文