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 get
int leLista(char* nome)
FILE *ficheiro = fopen(nome, "rb");
int cnt = -1;
if (ficheiro != NULL)
auxiliar = (Restaurante*)malloc(sizeof(Restaurante));
cnt = fread(auxiliar, sizeof(Restaurante), 1, ficheiro);
printf("batatas %s\n", auxiliar->nome);
if (cnt == 1)
}while(cnt != 0);
int valor = fclose(ficheiro);
What am doing wrong?
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