I think it's not necessary to use malloc since the assisgment don't specify it's must be.
So i use a regular fread file
Code:
int listarTop(struct jogador *j)
{
int retorno, cont = 0;
FILE *f;
if ((f= fopen("registos.dat", "rb")) == NULL)
{
printf("Erro ao abrir ficheiro\n");
}
printf ("\n*=============================================================================*\n");
printf ("| >>>>Visualizacao de perguntas<<<< |\n");
printf ("*=============================================================================*\n");
printf (" \n");
retorno = fread(j, sizeof *j, 1, f);
while ( retorno == 1)
{
cont++;
printf("\nNome: %s",j->nome);
printf("\nNickname: %s",j->nick);
printf("\nPassword: %s",j->pass);
printf("\nLog : %d",j->log);
printf("\n");
retorno= fread(j, sizeof *j, 1, f);
}
printf(" \n\n %d perguntas registadas \n", cont);
printf ("*=============================================================================*\n");
fclose(f);
}
But i have a seg fault here.
retorno = fread(j, sizeof *j, 1, f);
The file exist since the error is after, and i use a function login where i put my user and pass and i can access.