0
I have to do some functions with these structs, but since Agenda has a contact struct array and in each contact has another data struct, how do I access the fields? Do I have to work each struct separately? Thanks in advance, follow the code.
typedef struct Data{
int dia,mes,ano;
}t_data;
typedef struct Contato{
char nome[40];
char fone[12];
int idade;
t_data dataNascimento;
}t_contato;
typedef struct Agenda{
t_contato contatos[200];
}t_agenda;
I don’t know if I understand your doubt well. In the way you’re doing, I think it would be to have a variable like
t_contato
being by nameAgenda
. Something like:t_contato Agenda[200]
. You would access:Agenda[indice].dataNascimento.Dia
, for example.– Kevin Kouketsu
Actually there were only two structures Contact and Agenda, but in the struct Contact there was this member that I understood as another struct: dataNascimento: Data(Day, month and year int). I was trying to answer as stated, but I think I’ll follow the way you suggested! Obg o/
– Lucas Santos
Yes, it really is another structure. And it’s normal to have one structure inside another. But I see the way I said more "correct" because then, all your agendas would have a limit of 200 contacts, could not be more or less. In the way you said, you can have an agenda with N contacts. For example>
t_contato AgendaDois[10]
. Unless the contact structure withinAgenda
was dynamic. I believe that someone with more conceptual knowledge can respond better soon.– Kevin Kouketsu
Dude you started doing your job ? to manipulate the STRUCT, if they are going to be passed by value or reference, if for value has a type of access the variable is by reference has another type, Note create function with VOID example: http://linguagemc.com.br/funcao-com-pass-referenced/
– Magic Oz
Yes! I saw some examples and I was aware of how to do it, but I was getting caught up in this part of accessing the structs the way they were presented.
– Lucas Santos