0

Pointer to struct with pointer members

Hello! I'm having a problem with the code below. I want it to read the name and the price of the product and then print them out. The members of the struct have to be pointers and I need to have a pointer to a struct. Thank you! https://code.sololearn.com/ce47f3rbZPqq/?ref=app

19th May 2019, 1:28 AM
MargaritaK
3 Réponses
+ 2
You need to allocate for each pointer separately. What you are doing now only allocates a struct with two pointers that point nowhere. here is the fix: https://code.sololearn.com/cpg40y479uef/?ref=app
19th May 2019, 2:17 AM
O A T S
O A T S - avatar
0
Thank you very much O A T S! Why shouldn't I dereference the name?
19th May 2019, 7:07 AM
MargaritaK
0
By dereferencing it you pass the value of the first character in the string instead of a pointer to it.
19th May 2019, 3:52 PM
O A T S
O A T S - avatar