include stdio include stdlib int main Start vars int long long fSize F

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
int main(){
//Start vars
int i;
long long fSize;
FILE *pFile;
char *buffer;
size_t result;
//Reading file
pFile = fopen("file.bin", "rb");
if (pFile == NULL) {perror("Can't read file!"); exit (1);}
//Getting file size
fseek (pFile , 0 , SEEK_END);
fSize = ftell (pFile);
rewind (pFile);
//Allocating memory for file
buffer = (char*) malloc(sizeof(char)*fSize);
if (buffer == NULL) {perror("Can't allocate memory for file!"); exit (2);}
//Copying the file
result = fread(buffer, sizeof(char), fSize, pFile);
if (result != fSize) {perror("Can't read the file!"); exit (3);}
//Printing the file
for(i = 0; i < fSize; i++){
printf("%02X ", buffer[i]);
if(i % 8 == 7) printf("\n");
}
//Terminating
fclose (pFile);
free (buffer);
return 0;
}