Post by unleashed on Oct 22, 2009 1:54:17 GMT -5
/* This Program Has Been Made By Unleashed...
It is a simple file viewer and can display any file in Hex And ASCII format...
The Source code has been tested under gcc under linux and it works fine...
If u face any bugs then contact at keyur.unleashed@live.com ...
Comments are welcomed
*/
#include <stdio.h>
#include <ctype.h>
int main()
{
char filename[10];
FILE *f1;
int i,o;
int opt;
o=0;
int x=1;
printf("Type the filename for which you wanna see the hex version : ");
scanf("%s",filename);
if (!(f1=fopen(filename,"rb")))
{
fprintf(stderr,"ERROR OPENING THE FILE!!!\n");
fprintf(stderr,"Please check the file name!!!\n");
return -1;
}
printf("Type the viewing option:-\n");
printf("1.Hex view\n");
printf("2.ASCII view\n");
scanf("%d",&opt);
if (opt==1)
{
while (!(feof(f1)))
{
if(ferror(f1)!= 0)
{
fprintf(stderr,"Error has occurred!!!");
fprintf(stderr,"Quitting!!!");
}
i=fgetc(f1);
printf("%02X ",i);
o++;
if (o==(40*x))
{
printf("|\n");
x++;
}
}
printf("|\n");
}
else if(opt==2)
{
while (!(feof(f1)))
{
if(ferror(f1)!= 0)
{
fprintf(stderr,"Error has occurred!!!");
fprintf(stderr,"Quitting!!!");
}
i=fgetc(f1);
if (!(isprint(i)))
{
printf(".");
}
else
{
printf("%c",i);
}
o++;
if (o==(40*x))
{
printf("\n");
x++;
}
}
printf("\n");}
fclose(f1);
return 0;
}
Thanks,
Unleashed