Monday, December 27, 2010

ran some tests



The key here is that I'm trying to see evidence that the file pointer is moving after fread gets data.

I'll need to restate obvious things to work through this. My file pointer, plxfilepointer, is a variable that contains a memory address. This memory address is a location in memory where my file is being held (to the best of my knowledge that's how fopen works).

A memory address is just a number, and I figured that printing to screen this number before and after fread would do something interesting. It doesn't. It just prints the same number twice.

For kicks I decided to change the printf lines - instead of printing plxfilepointer, I printed *plxfilepointer. I de-referenced it such that I'm printing out whatever exists at the memory address that plxfilepointer points to. IF plxfilepointer isn't changing (it holds the same memory address before and after) then the de-referenced value shouldn't change, right? Well... that's not what I'm seeing.

Without de-referencing plxfilepointer I see this output:

File pointer is 760C2960
File pointer after fread 760C2960

I take this to be the memory address that plxfilepointer contains, which should the the memory address of the start of my file.

If I print out the de-referenced plxfilepointer, I get this:

File pointer is 00000000
File pointer after fread 00644830

I don't understand what this means. The "after fread" number is random, but the first pre-fread is always 00000000. I thought that the de-referenced file pointer would point to my file's location or the contents of the file - I still am not clear on what type FILE is. In either case the first number shouldn't be 0 (that's neither an address OR contents) or random (address maybe, contents no).

I'm growing convinced that there is something about FILE pointers and fread that are special that I need to not worry too much about.

No comments:

Post a Comment