Hi....again
I was testing my program then i realise that i have a bug in my code.
Well, i have a struct file with nickname and pass
When i use the fread i see 3 registered users.
When i want to login, i have only 2, and only one can log (fisrt one)
If i use the fread() all the values are not read??
My code is this one
Code:
int login()
{
struct jogador j;
int reg=0, op;
char usr1[30], pass[30], auxiliar[30];
FILE *fp;
fp=fopen("registos.dat", "rb+");
printf ("\n*=============================================================================*\n");
printf ("| >>>> Login de Jogadores <<<< |\n");
printf ("*=============================================================================*\n");
printf (" \n");
printf("\n1- Registar | 2- Registado\n");
scanf("\n%d", &op);
getchar();
if(op==1)
{
registo();
}
if(op==2)
{
reg=fread(&j, sizeof j, 1, fp);
while(reg==1)
{
reg++;
printf("\n %d players\n", reg);
printf("\nnickname: \n");
fgets(auxiliar,29,stdin);
sscanf(auxiliar,"%[^\n]",usr1);
fseek(fp, (reg - 1) * sizeof j, SEEK_SET);
if(strcmp(usr1,j.nick)==0)
{
printf("\npassword: \n");
fgets(auxiliar,29,stdin);
sscanf(auxiliar,"%[^\n]",pass);
if(strcmp(pass,j.pass)==0)
{
system("cls");
printf("\n 1 - Jogo curto (2 perguntas) \n");
printf("\n 2 - Jogo medio (4 perguntas) \n");
printf("\n 3 - Jogo grande (8 perguntas)\n");
printf ("*=============================================================================*\n");
scanf("%d", &op);
getchar();
switch (op)
{
case 1:
gp1_Ques(usr1);
break;
case 2:
gp1_Ques2(usr1);
break;
case 3:
gp1_Ques3(usr1);
break;
default:
printf("\nOpcao invalida\n");
return 0;
}
}
else
{
printf("Password errada");
return 0;
}
}
else
{
printf("Nickname errado");
return 0;
}
}
}
fclose(fp);
return 0;
}
So, if i have 1 player is ok, if i have 20, only the first one in the list can log...