#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;
}