I need an help to solve an exercise.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct p_prodotto {
char *costo;
char *quantita;
};
typedef struct p_prodotto id_prezzo;
struct partecipante {
id_prezzo *prezzo;
unsigned short codice;
};
struct partecipante persona[1] = {{{"We", "Ciao"},100}};
int main()
{
printf ("%s", persona[0].prezzo.costo); // This doesn't works
return 0;
}
I have the struct p_prodotto with two char pointers inside. There is the typedef, then there is another struct “partecipante” that calls to the type of the struct above.
Is this a case of struct of struct? If so, I need to create an array. I did it like this:
struct partecipante persona[1] = {{{"We", "Ciao"},100}};
Am I doing it wrong? If it is correct, how can I access the “costo” and “quantita” fields?
Thanks in advance for the help.
That initialises the struct’s first member as a
struct p_prodotto, but it is declared as a pointer to that. Either changestruct partecipantetoor initialise it in a different way.
For example
if you can’t change the definition of
struct p_prodotto.