Home Segments Index Top Previous Next

375: Mainline

Next, the original program contains a for statement that does reading and writing:

for (limit = 0; 
     2 == scanf ("%lf%i", &price, &number); 
     ++limit) { 
  trades[limit].price = price; 
  trades[limit].number = number; 
} 

You need to add a statement that allocates new space for a trade object and deposits the address of the newly allocated space into the appropriate array location:

trade_pointers[limit] = (struct trade*) malloc (sizeof (struct trade)); 

Also, you need to modify the existing statements to dereference pointers:

trade_pointers[limit] -> price = price; 
trade_pointers[limit] -> number = number; 

The structure-pointer operators appear in the assignment statements, because you are working with an array of trade pointers, rather than of trade objects.