I´ve been doing a project in C
about making a team and saving it in a file so it can be read in the next execution. And right now i´m developing a function that should ask the user for a player in the team and eliminate the one that the user has choosen.
For that, i´m using a for loop
that prints every player present in the object of the structure and then im asking the user to choose which player to delete.
Then i have a switch case
because, depending on the id of the player that was the user's choice the players above should move one position down.
The code is the following:
int eliminarjogadores(jogador players[NUM], FILE *fplayers, int nj){
int a=0;
int i=0;
printf("Qual o jogador que pretende eliminar?\n");
for(i=0;i<nj;i++){
printf("%i - %s\n",i+1, players[i].nome);
}
scanf("%i",a);
switch (a) {
case 1:
printf("fds...\n" );
while(a<nj&&a<NUM){
strcpy(players[a-1].nome,players[a].nome);
a++;
}
if(a==NUM-1){
strcpy(players[a-1].nome,"");
}
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
break;
default:
printf("Opção inválida!\n");
break;
}
return nj-1;
}
The code is not finished yet, but if the user choose option one it should have substituted the name of the first player for the name of player two, the second player for the third and so on until there is no players left on the object of the structure and then the last player should have a empty name like "".
But when i try to run the code and select theese options i have this output: Code output
It does not enter the switch case, and i don't know if the problem is on the switch case itself or in the scanf or in other place, can you guys help me?