-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aldebaro
committed
Nov 25, 2016
1 parent
47de235
commit 5b80744
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* Prints each byte of a file */ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#define DATE "Aldebaro. Nov/24/2016" | ||
int main(int argc, char *argv[]) { | ||
FILE *fp; | ||
int k,i,j,k2; | ||
unsigned char x1; | ||
char s[4096]; | ||
puts(DATE); | ||
if(argc!=4) { | ||
printf("Usage: %s <input file> <first byte> <last>\n",argv[0]); | ||
puts("Example: inspectFile myfile.bin 0 30"); | ||
exit(1); | ||
} | ||
sprintf(s,"%s",argv[1]); | ||
fp=fopen(s,"rb"); | ||
if (fp==NULL) { | ||
puts("Erro abertura do arquivo"); | ||
exit(1); | ||
} | ||
for (i=0;i<atoi(argv[2]);i++) { //skip bytes as specified by user | ||
fread(&x1,sizeof(unsigned char),1,fp); | ||
} | ||
k=0; | ||
for(i=atoi(argv[2]);i<atoi(argv[3]);i++,k++) { | ||
k2=fread(&x1,sizeof(unsigned char),1,fp); | ||
if(k2 != 1) { | ||
puts("End of file!"); | ||
break; | ||
} | ||
printf("%d\t%d (decimal)\t%x (hexa)\t(%c)\n",k,(short int)x1,(short int)x1,x1); | ||
} | ||
puts("Happy end!"); | ||
fclose(fp); | ||
} |