编写C语言,实现读取一个二进制文件,以16进制格式显示在屏幕上
1个回答
展开全部
#include <stdio.h>
int main()
{
FILE *fp1 = NULL;
char buf1[100] = {0};
int i;
fp1 = fopen("1.txt", "r");
for(i=0;i<5;i++)
{
fread(&buf1[i], sizeof(char), 1, fp1);
printf("0x%x, ", buf1[i]);
}
fclose(fp1);
return 0;
}
1.txt为
baidu
C:\Documents and Settings\Administrator\桌面>t
0x62, 0x61, 0x69, 0x64, 0x75,
C:\Documents and Settings\Administrator\桌面>
int main()
{
FILE *fp1 = NULL;
char buf1[100] = {0};
int i;
fp1 = fopen("1.txt", "r");
for(i=0;i<5;i++)
{
fread(&buf1[i], sizeof(char), 1, fp1);
printf("0x%x, ", buf1[i]);
}
fclose(fp1);
return 0;
}
1.txt为
baidu
C:\Documents and Settings\Administrator\桌面>t
0x62, 0x61, 0x69, 0x64, 0x75,
C:\Documents and Settings\Administrator\桌面>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询