Hi,everybody.Following is an simple C programm which want to display the content of a file with corresponding hex.If one letter is a undisplayed then replace it with '.' .
info and code:
info:
[root@localhost guai]# gcc disp.c -o disp.exe
disp.c:29:9: empty character constant
disp.c: In function `main':
disp.c:47: wrong type argument to increment
#include <stdio.h>
int main(int argc,char **argv)
{
char letter[17];
int c,i,cnt;
FILE *fp;
if(argc!=2)
{
printf("\7USAGE:disp filename");
exit();
}
if((fp=fopen(argv[1],"r"))==NULL)
{
printf("\7file %s can't opened\n",argv[1]);
exit();
}
cnt=0;
do
{
i=0;
printf("%06x:",cnt*16);
while((c=fgetc(fp))!=EOF)
{
printf("%02x",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);
}