int main()
{
FILE *fp = fopen("/root/ds/filehandling/a.pdf", "rb");
unsigned char magic[4];
fread((void *)magic, 1, 4, fp);
cout << hex << "magic:";
for (int i = 0; i < 4; i++)
cout << " 0x" << int(magic[i]);
cout << dec << endl;
return 0;
}
The problem here is I have to specify the extension then only i would get the magic number , but my objective is to specify the name of file without giving its extension so that on comparing magic number i could determine its type.
This is what i want:
int main() {
FILE *fp = fopen("/root/ds/filehandling/a", "rb");
unsigned char magic[4];
fread((void *)magic, 1, 4, fp);
cout << hex << "magic:";
for (int i = 0; i < 4; i++)
cout << " 0x" << int(magic[i]);
cout << dec << endl;
return 0;
}
ouput : magic: 0x25 0x50 0x44 0x46
but I a m getting "SEGMENTATION FAULT"