#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct aluno
{
int matricula;
char nome[30];
float n1, n2, n3;
};
typedef struct elemento* Lista;
struct elemento
{
struct aluno dadosAlunos;
struct elemento *prox;
};
typedef struct elemento Elem;
void imprime_lista(Lista li){
while (li != NULL)
{
printf("Nome: %s ", li
->dadosAlunos.
nome /*<--diferente aqui*/); printf("\nMatricula: %d ", li
->dadosAlunos.
matricula); printf("\nN1: %f ", li
->dadosAlunos.
n1); printf("\nN2: %f ", li
->dadosAlunos.
n2); printf("\nN3: %f ", li
->dadosAlunos.
n3);
li = li -> prox;
}
}
int inserir_no_inicio_da_lista (Lista* li, struct aluno al)
{
if (li == NULL)
{
return 0;
}
Elem
* no
= (Elem
*) malloc(sizeof(Elem
));
if (no == NULL)
{
return 0;
}
no -> dadosAlunos = al;
no -> prox = (*li);
*li = no;
return 1;
}
int main()
{
int varAux = 0;
struct aluno estruturaAlunoAuxiliar;
Lista listaDeAlunos;
listaDeAlunos = NULL;
estruturaAlunoAuxiliar.matricula = 1;
strcpy(estruturaAlunoAuxiliar.
nome, "Thiago Ferreira"); estruturaAlunoAuxiliar.n1 = 7;
estruturaAlunoAuxiliar.n2 = 6;
estruturaAlunoAuxiliar.n3 = 9;
varAux = inserir_no_inicio_da_lista (&listaDeAlunos, estruturaAlunoAuxiliar);
imprime_lista(listaDeAlunos);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKc3RydWN0IGFsdW5vCnsKICAgIGludCBtYXRyaWN1bGE7CiAgICBjaGFyIG5vbWVbMzBdOwogICAgZmxvYXQgbjEsIG4yLCBuMzsKfTsKdHlwZWRlZiBzdHJ1Y3QgZWxlbWVudG8qIExpc3RhOwoKc3RydWN0IGVsZW1lbnRvCnsKICAgIHN0cnVjdCBhbHVubyBkYWRvc0FsdW5vczsKICAgIHN0cnVjdCBlbGVtZW50byAqcHJveDsKfTsKdHlwZWRlZiBzdHJ1Y3QgZWxlbWVudG8gRWxlbTsKCgoKdm9pZCBpbXByaW1lX2xpc3RhKExpc3RhIGxpKXsKICAgIHdoaWxlIChsaSAhPSBOVUxMKQogICAgewogICAgICAgIHByaW50ZigiTm9tZTogJXMgIiwgbGktPmRhZG9zQWx1bm9zLm5vbWUgLyo8LS1kaWZlcmVudGUgYXF1aSovKTsKICAgICAgICBwcmludGYoIlxuTWF0cmljdWxhOiAlZCAiLCBsaS0+ZGFkb3NBbHVub3MubWF0cmljdWxhKTsKICAgICAgICBwcmludGYoIlxuTjE6ICVmICIsIGxpLT5kYWRvc0FsdW5vcy5uMSk7CiAgICAgICAgcHJpbnRmKCJcbk4yOiAlZiAiLCBsaS0+ZGFkb3NBbHVub3MubjIpOwogICAgICAgIHByaW50ZigiXG5OMzogJWYgIiwgbGktPmRhZG9zQWx1bm9zLm4zKTsKCgogICAgICAgIGxpID0gbGkgLT4gcHJveDsKICAgIH0KICAgIHByaW50ZigiXG4iKTsKfQoKaW50IGluc2VyaXJfbm9faW5pY2lvX2RhX2xpc3RhIChMaXN0YSogbGksIHN0cnVjdCBhbHVubyBhbCkKewogICAgaWYgKGxpID09IE5VTEwpCiAgICB7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CgogICAgRWxlbSogbm8gPSAoRWxlbSopIG1hbGxvYyhzaXplb2YoRWxlbSkpOwoKICAgIGlmIChubyA9PSBOVUxMKQogICAgewogICAgICAgIHJldHVybiAwOwogICAgfQoKICAgIG5vIC0+IGRhZG9zQWx1bm9zID0gYWw7CiAgICBubyAtPiBwcm94ID0gKCpsaSk7CgogICAgKmxpID0gbm87CgogICAgcmV0dXJuIDE7Cn0KCmludCBtYWluKCkKewogICAgaW50IHZhckF1eCA9IDA7CgogICAgc3RydWN0IGFsdW5vIGVzdHJ1dHVyYUFsdW5vQXV4aWxpYXI7CiAgICBMaXN0YSBsaXN0YURlQWx1bm9zOwoKICAgIGxpc3RhRGVBbHVub3MgPSBOV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