Hi!
I'm trying to code a program that needs to store data in a binary file.
I already did the first try of the code and it works fine except when the file hasn't been created yet and I try to read. I thought that the fopen fuction would just return NULL in this case.
My code to read is:
It generates a segmentation fault. If I run it in gdb I getCode:int leLista(char* nome) { FILE *ficheiro = fopen(nome, "rb"); int cnt = -1; Restaurante* auxiliar; if (ficheiro != NULL) { do{ auxiliar = (Restaurante*)malloc(sizeof(Restaurante)); cnt = fread(auxiliar, sizeof(Restaurante), 1, ficheiro); printf("batatas %s\n", auxiliar->nome); if (cnt == 1) { inserir(criaNo(auxiliar)); } }while(cnt != 0); imprimeLista(); } int valor = fclose(ficheiro); return cnt; }
What am doing wrong?Code:Program received signal SIGSEGV, Segmentation fault. 0xb7eb25dd in fclose () from /lib/tls/i686/cmov/libc.so.6 (gdb) print errno Cannot find thread-local variables on this target
Thanks in advance



LinkBack URL
About LinkBacks



