Skip to content

Commit

Permalink
Prints all bytes of a file
Browse files Browse the repository at this point in the history
  • Loading branch information
Aldebaro committed Nov 25, 2016
1 parent 47de235 commit 5b80744
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions C_Language/inspectFile.c
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);
}

0 comments on commit 5b80744

Please sign in to comment.