I am new to C and the problem i am facing is that that i have a binary file which is unpacked (i.e its in a certain format)..
What i am suppose to do is to pack it and unpack it again and see if its equal to the original unpacked version.
One thing worth mentioning: i have been told the packing (i.e convert to packed) and unpacking(i.e convert to unpacked) function works well.. Just want to confirm it for myself and learn a bit of C...
I have two points where i think i am doing mistake
1 : the way i am reading the file
2 : I am not properly considering the variable type of packed and unpacked (i.e for packed it is unsigned char * and for unpacked it is short * )
int main(void) { FILE *fp; unsigned char* packed ; short* unpacked; size_t result; int fileSize; fp = fopen(FILENAME, "rb"); fseek (fp , 0 , SEEK_END); fileSize = ftell (fp); rewind (fp); unpacked = (short*) malloc (sizeof(char)*fileSize); result = fread(unpacked,1,fileSize,fp); short *originalUnpacked = unpacked; convert_to_packed(&unpacked, &packed); convert_to_unpacked(&unpacked, &packed); if (originalUnpacked == unpacked) { puts ("Thats it !!"); } fclose(fp ); return EXIT_SUCCESS; }