I made this method for a test and for some reason the malloc is not working. When I comment it it does work, but otherwise it will just say the program has stopped working.
typedef struct { int NroUSP; // chave primária int curso; int estado; int idade; bool valido; // para exclusão lógica } REGISTRO; typedef struct s { int NroUSP; // chave primária int curso; int estado; int idade; bool valido; struct s* prox; } NO; typedef struct { NO* inicio; } LISTA; These are the structures I used ^
EDIT: THE PROBLEM WAS THIS ASTERISK RIGHT BEFORE AUX
void ex6(){ REGISTRO* aux; FILE *arq = fopen("C:\\Users\\jujuc_000\\Desktop\\Teste\\dados.bin","rb"); FILE *arq2 = fopen("C:\\Users\\jujuc_000\\Desktop\\Teste\\ex6.bin","wb"); LISTA l; l.inicio = NULL; NO*p = (NO*)malloc(sizeof(NO)); // this is the test malloc if(arq){ while(1==fread(&aux,sizeof(REGISTRO),1,arq)){ /*p = (NO*)malloc(sizeof(NO)); // this is the one I want to keep p->NroUSP = aux->NroUSP; p->curso = aux->curso; p->estado = aux->estado; p->idade = aux->idade; p->valido = aux->valido; if(!l.inicio){ l.inicio = p; } p=p->prox;*/ } } fclose(arq); fclose(arq2); }
mallocor atp=p->prox?