home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
zip
/
language
/
sozosun.zoo
/
hex.c
next >
Wrap
C/C++ Source or Header
|
1991-02-09
|
1KB
|
52 lines
/*****************************************************/
/* simple program to do a hex dump of a file */
/*****************************************************/
#include <stdio.h>
main(argc,argv,envp)
int argc;
char **argv, **envp;
{
FILE *fp;
int col,pos;
char buf[33];
/* for each file on the command line */
while(argc-- > 1) {
if((fp=fopen(argv[argc],"rb")) == NULL) {
printf("hex: warning - unable to open file %s\n",argv[argc]);
continue;
}
printf("hex: dumping file %s\n\n",argv[argc]);
/* read and dump the file */
pos=0;
while(feof(fp) == 0) {
printf("%4.4x | ",pos);
for(buf[0]=fgetc(fp),
buf[1]=fgetc(fp),
col=1;
col < 16;
pos++,
buf[++col] = fgetc(fp),
buf[++col] = fgetc(fp)) {
printf("%4.4x ",(unsigned short)
(buf[col-1]*256+buf[col]));
}
printf(" | ");
for(col=0; col <= 16; col++) {
if(buf[col] >= 0x20 && buf[col] <= 0x7e) {
printf("%c",buf[col]);
}
else {
printf(" ");
}
}
printf("\n");
}
fclose(fp);
}
}