I need help understanding why my pointer doesn't update
Code:
int readThis( unsigned int addr, void* mybuf ) {
lseek( infd, rootAddr, SEEK_SET ); // root Addr calculation omitted from thread
read( infd, mybuf, PAGESIZE); // PAGESIZE is the global variable used for the block size
bcopy(mybuf, &VMCACHE[victimPage][0], PAGESIZE); // copies the contents read from the previous instruction into a cache (char VMCACHE[x][y])
mybuf = &VMCACHE[victimPage][offSet]; // attempts to set the contents to the specific data within the cache
Record* pRecord = mybuf;
Record ppRecord = *pRecord;
printf("%s\n", ppRecord.string); // actually outputs the right data
return 0;
}
Code:
int listArtists(unsigned int addr) {
Record thisbuf;
readThis( addr, &thisbuf ); // calling the function above
printf("Buffer:%s\n", thisbuf.string); // outputs different data from mybuf, although it seems like they point to the same set of data
}
Basically, what my code does is update fetch a block sized amount of data and tries to store it into the cache. Then I try to update the buf to hold the selected value within that block.
I have deleted a lot of extraneous code also, but the main thing is that the first printf involving ppRecord.string outputs something entirely different from thisbuf.string.
Based on the code above, since the ppRecord points to the same destination of mybuf and mybuf is the pointer passed by thisbuf, shouldn't the two printf statements be equivalent?
ADDITIONAL INFORMATION:
I forgot to mention that thisbuf.string prints the original value assigned to the location of mybuf from the read() function. Therefore thisbuf never gets updated from any new assignment after the initial read.