If dadosAluno
is not a pointer then it is accessed with .
.
The print function should then be:
void imprime_lista(Lista* li){
while (li != NULL)
{
printf("Nome: %s ", li->dadosAluno.nome /*<--diferente aqui*/);
li = li -> prox;
}
printf("\n");
}
Notice that it began with ->
because li
is a pointer. If it were not (although in these cases it is necessary for it to end in NULL
) it would be li.dadosAluno.nome
.
If dadosAluno
was declared as a pointer, like this:
struct elemento {
struct aluno *dadosAlunos;
struct elemento *prox;
};
So access to the function would look like this:
li->dadosAluno->nome
However this would imply allocating this object with malloc
before using and removing it when it was not needed with free
, which would considerably complicate the code.
Edit :
The error you are having:
request for member 'dataAlumni' in something not a structure or union
It actually has to do with a subtle error in the code, here:
void imprime_lista(Lista* /*<--aqui*/ li){
The parameter must be Lista li
, not Lista* li
, because Lista
is already a typedef
for a pointer, as you can see here:
typedef struct elemento* Lista;
Soon I was using a pointer for a pointer! As if it were struct elemento**
Edit 2 :
Just like in my last statement, Lista
is already a pointer to a node in the list, so it is not supposed to use Lista*
anywhere, unless it is as a parameter of a function that changes the start of the list .
This causes your main
to be:
int main()
{
int varAux = 0;
struct aluno estruturaAlunoAuxiliar;
Lista listaDeAlunos; //sem Lista* agora
listaDeAlunos = criar_lista(); //este agora deve devolver um Lista e não Lista*
estruturaAlunoAuxiliar.matricula = 1;
strcpy(estruturaAlunoAuxiliar.nome, "Thiago Ferreira");
estruturaAlunoAuxiliar.n1 = 7;
estruturaAlunoAuxiliar.n2 = 6;
estruturaAlunoAuxiliar.n3 = 9;
//deve rever esta função pois ela para estar bem implementada deveria receber um
//Lista* para poder modificar o inicio da lista, o que faz com que deva ser passado o
//endereço da lista aqui no main
varAux = inserir_no_inicio_da_lista (&listaDeAlunos, estruturaAlunoAuxiliar);
imprime_lista(listaDeAlunos); //imprime agora recebe Lista e não Lista*
return 0;
}
You will now have to adjust their functions to match this new main
in terms of parameters and returns.