I need to test if a file is a ELF file, to do this, i have to compare the first four bytes. The first bytes of the files begins with 0x7F 0x45 0x4C 0x46
.
I use fread(...) to read first four bytes out to an array. Printing the content of the array shows that the file contains the hex numbers described over.
I have tried some easy methods to compare each byte with the hex code, like this
if(bytes[0] != "0x7f" || bytes[1] != "0x45 ....) printf("Error, not ELF file")
But as i understand, i cant compare bytes this way. Which way should i compare the content in the array to get this correct ?