Here's what I'm trying to do. I have a char pointer that contains a pagefile size of records in it that I've read from disk. This file is a binary file. From this I am trying to bsearch the pointer.
So, in essence each record in the file is 50 bytes long, with a pageFile being read in at a time.
my bsearch is as follows, where sid is the id that I'm searching on and dest is the char pointer with 50 * pageSize bytes of data:
bsearch(&sid, dest, pageSize, 50, comparator);
this is my comparator function:
I have verified that the data is complete, but for some reason, there is garbage data in ca, but in cb the correct data is present. Even more bizarre is I'm not getting any segfaults to indicate that there is in fact garbage data about.
unsigned int comparator(const void* a, const void* b)
char* ca = (char*)a;
char* cb = (char*)b;
unsigned int ta = 0;
unsigned int tb = 0;
/* the 16th element is where the id starts, thats what I'm
searching on */
memcpy(&ta, &(ca), sizeof(unsigned int));
memcpy(&tb, &(cb), sizeof(unsigned int));
return (ta - tb);