assigning values to a dynamically allocated array of structures
Hi,
I am trying to dynamically create an array of structures of type page. The page struct looks like this:
Code:
typedef struct
{
unsigned short int proc_no;
unsigned short int page_no;
} page;
Then in a function called set_trace, I am using malloc to dynamically create the array. I believe thus far my code is correct, but the next thing I'm trying to do is enter values into this array of structs. This is what my set_trace function looks like.
Code:
void set_trace( unsigned short int proc_no, unsigned short int trace[], page *pPter )
{
pPter = malloc( sizeof( page ) * trace_size );
for( int n = 0; n <= trace_size; n++ )
{
pPter.process_number = proc_no;
pPter.page_number = trace[n];
}
}
For each iteration of the loop, I am trying to assign the proc_no and the value at trace[n] to the nth page in the array. Can someone show me how to do this?