tags:

views:

30

answers:

1

I'm writing a program with struct Record. As I read in records from text in a loop, I assign them to buffer before saving buffer into the array. nRange is just the total number of records being read.

Record *storage; 
storage = (Record*)malloc(nRange*sizeof(Record)); 
Record buffer;
storage[i] = buffer;

I want to access storage[i] in order to check that the record is being saved to memory, but I can't quite get the syntax. I was trying something like:

printf("%d \n", &storage[i].x);

But I think this is just giving me the address of the x value of the Record at storage[i]. If anyone could give me the exact syntax I'd greatly appreciate it.

+1  A: 

You're overthinking things. You just write storage[i], just like when you assigned it.

printf("%d \n", storage[i].x);
Chuck
I tried that before too and it gave me some large negative number....but I double checked my code and I was using the same variable for 2 nested loops and that was throwing me off. Thanks!