Relation between structs in C

Asked

Viewed 113 times

1

I have the following scenario:

typedef struct Unidade{
    int cod;
} und;

typedef struct Produto{
    int cod;
    char nome[100];
    und unidade;
} prod;

As you can see I have a unit type variable inside the product. How I write to this variable and how to access it?

In unidade record like this: u

nidade.cod = 10;

In produto would look like when recording this variable unidade? And how I would read this variable later?

  • How is your code creating an instance of this structure?

  • in main this so Prod products[100]; //list of products und units[20]; // list of units

  • Edit the question, put it right as it is.

1 answer

1


Basically is

produto.unidade.cod = 10;

where produto is the instance variable.

The reading would be done like this:

produto.unidade.cod

I put in the Github for future reference.

If the object is created as pointer then it would have to use the operator -> in place of ..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.