简体   繁体   English

使用fread()读取二进制文件

[英]Read binary file using fread()

I'm trying to read a binary file with fread() function. 我正在尝试使用fread()函数读取二进制文件。
I want to read 2 byte every time (UTF-16 file). 我想每次读取2个字节(UTF-16文件)。
The relative code: 相对代码:

char words[2];
while(fread(&words, sizeof(words), 1, sFile))
//do somthing...

The information from the file is stored only in the first place of the array, and the second stay as zero. 来自文件的信息仅存储在数组的第一个位置,第二个保持为零。 Any idea? 任何想法? Thanks 谢谢

Thank to you all, I found the mistake - 谢谢大家,我发现了错误-
In UTF-16, every char is 2 byte, and the "regular" chars are with zero in the 2nd byte. 在UTF-16中,每个字符为2个字节,“常规”字符在第二个字节中为零。
Again, thank you. 再次谢谢你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM