views:

73

answers:

3

My question's pretty basic, but it's been a while. I'm reading in a text file and saving numbers in the text to a struct 'Record'. After I read text to my Record buffer, I want to place it in an area of memory.

typedef struct
{
 int line_status[64];
 float line_data[64], relativetime;
 unsigned long blkhdr_ticks;
} Record;

Record *storage; 
storage = (Record*)malloc(nRange*sizeof(Record)); 
Record buffer;

Where nRange is some random number, and buffer is a Record with values, though I haven't listed my code that assigns these to the buffer. I thought the syntax was something like:

&storage = buffer;

But I know that's not right. Any help would be greatly appreciated.

+3  A: 

You should be able to say *storage = buffer; or storage[0] = buffer;.

cHao
+4  A: 

You can also treat storage as an array.

storage[0] = buffer;
storage[1] = anotherBuffer;
...
storage[nRange-1] = lastBuffer;
thesam
A: 

Since storage can also be regarded as an array of nRange records (I guess that really is your intention) you can simply do:

 storage[0] = buffer;
 storage[someOtherIndex] = buffer;
DarkDust