1
I did this function, but I do not know if it is right, there is no error in the compilation, but it gives an error when the prompt
that the program has stopped working.
Insertion at the beginning:
int inserir_no_inicio_da_lista (Lista* li, struct aluno al){
if (li == NULL){
return 0;
}
Elem* no;
no = (Elem*) malloc(sizeof(Elem));
if (no == NULL){
return 0;
}
no -> dadosAlunos = al;
no -> prox = (*li);
*li = no;
return 1;
}
Structures:
struct aluno {
int matricula;
char nome[30];
float n1, n2, n3;
};
typedef struct elemento* Lista;
//Arquivo ListaDinEncad.c
struct elemento {
struct aluno dadosAlunos;
struct elemento *prox;
};
typedef struct elemento Elem;
Lista* criar_lista();
Creates List:
Lista* criar_lista() {
Lista* li;
li = (Lista*) malloc(sizeof(Lista));
if (li != NULL){
*li = NULL;
}
return li;
}
WHAT MISTAKE IT MAKES ?
– Dev
Also missing are the
struct
s andtypedef
s so that everyone can understand how they are defined and understand the types that come in the function.– Isac
All right, I’ve edited for better understanding.
– André
The code seems to be working for me. See here. How is the function
criar_lista
? And how is themain
?– Isac
The main is equal to what is there in the link, the function I just added.
– André