16进制形式显示文件--帮忙修改
#include<stdio.h>#include<stdlib.h>
void main(int argc, char *argv[])
{
char letter[17];
int c, i, cnt;
FILE *fp;
if (argc != 2)
{
puts("\7usage:dumpf filename");
exit(0);
}
if ((fp = fopen(argv[1], "r")) == 0)
{
printf("\7file%scan't opened\n", argv[1]);
exit(0);
}
cnt = 0;
do
{
i = 0;
printf("%6x", cnt*16);
while ((c = fgetc(fp)) != EOF)
{
printf("%2x", c);
if (c < ' ' || c > 0x7e)
letter[i] = '.';
else
letter[i] = c;
if (++i == 16)break;
}
letter[i] = '\0';
if (i != 16)
for (;i < 16;i++)printf(" ");
printf("%s\n", letter);
cnt++;
}while (c != EOF);
fclose(fp);
}