Having converted trade_price
's ordinary trade structure
parameter, t
, into a trade
pointer parameter,
tptr
, your program must, of course, dereference tptr
inside the trade_price
function to identify a particular trade
structure object in the trades
array. Accordingly, instead of
expressions, such as t.price
, that read structure variables in a
trade
copy, you need expressions that read structure
variables in a trade
object identified by a dereferenced pointer.
The redefined trade_price
function is as follows:
double trade_price (struct trade *tptr) { return (*tptr).price * (*tptr).shares}
Note that you must enclose *tptr
in parentheses to refer to the price
of the trade
object to which tptr
points, because the
structure-member operator, the period, has precedence higher than that of
the dereferencing operator, the asterisk. Accordingly, a version without
parentheses, *tptr.price
, is equivalent to *(tptr.price)
,
which means produce the object pointed to by a pointer stored,
peculiarly, in the price member variable of a pointer to a trade object.
What you want, of course, is the version that means produce the value
stored in the price member variable of the dereferenced pointer to a trade
object.