65,208
社区成员
发帖
与我相关
我的任务
分享
nclude <stdio.h>
int main()
{
FILE* file = fopen("1.data", "rb");
unsigned char ch = 0;
int cnt = 0;
if (!file)
{
printf("can not open the file\n");
return 1;
}
printf("open file success\n\n");
while (1)
{
fread(&ch, sizeof(ch) , 1, file);
printf("%s0x%02x ", cnt++ % 10 ? "" : "\n", ch);
if (feof(file))
break;
}
fclose(file);
return 0;
}
// test
open file success
0x61 0x64 0x66 0x61 0x73 0x66 0x61 0x73 0x64 0x66
0x61 0x73 0x66 0x61 0x73 0x64 0x66 0x61 0x73 0x64
0x66 0x61 0x73 0x64 0x66 0x61 0x73 0x66 0x66 请按任意键继续. . .