0
Does anyone know why the value of i
change in condition else if(i==721)
? It changes strangely, as you can see in video of debuging.
teamfile=fopen("team.txt", "r");
if(fgets(c, 3, teamfile)==NULL){
printf("Please add one team at least before try to add players or managers.\n");
}
else{
playerfile=fopen("player.txt", "r");
for(i=1; i<=722; i++){
if(fgets(c, 250, playerfile)==NULL && i<720){
do{ //NAME
printf("Name: ");
getchar();
gets(c);
w=0;
for(j=0; j<49; j++){ //<49 supondo que, para o string máximo, o c[49]=\0
if(c[i]>32 && c[i]<65){
w=1;
printf("Invalid characters. Try again. \n"); break;
}
}
}while(w==1);
strcpy(player[i].name, c);
do{ //BIRTH DATE
w=0;
printf("Player birth date (dd mm yyyy): ");
scanf("%i %i %i", &d, &m, &y);
w=dateverific(d, m,y);
}while(w==1);
player[i].birth.day=d;
player[i].birth.month=m;
player[i].birth.year=y;
nations(i); //NATION
positions(i); //POSITION
teamlists(i, a); //TEAM
fclose(playerfile);
playerfile=fopen("player.txt", "a");
fprintf(playerfile, "%s %d %33s %d %d %d %s %s\n", player[i].position, i, player[i].team, player[i].birth.day, player[i].birth.month, player[i].birth.year, player[i].nation, player[i].name); // explicar troca de id pela position realacianado com o fscafn do string clube name
fclose(playerfile);
break;
}
else if(i==721){
printf("Impossible to add more players, all team are full.");
}
else{
}
}
}
How your variable was declared
i
?– Igor Cavalcanti
Usually, int i=1;
– Fezudo