#include <stdio.h>
struct tetris{
char nome[16];
int pontuacao;
};
int main(){
int i, nteste = 1, J, k, total = 0, maior, menor, pontos;
while (scanf("%d\n", &J) && J != 0){
struct tetris jogador[J];
for (i = 0; i < J; i++){
fgets(jogador[i].nome, 16, stdin);
printf("LI NOME");
total = 0;
maior = 0;
for (k = 0; k <= 11; k++){
if (k == 11)
scanf("%d\n", &pontos);
else
scanf("%d", &pontos);
printf("LI PONTO");
total += pontos;
if (pontos > maior)
maior = pontos;
else
if (pontos < menor)
menor = pontos;
if (k == 0)
menor = maior;
}
jogador[i].pontuacao = total - maior - menor;
}
printf("ACABEI");
for (k = 0; k < J; k++){
printf("%s %d", jogador[k].nome, jogador[k].pontuacao);
}
}
return 0;
}
After I type all the data, this way, for example:
4
Zezinho
100 123 133 333 400 300 129 200 360 340 200 600
Luizinho
60 50 120 250 170 190 190 220 260 270 290 300
Carlinhos
10 10 20 10 10 10 10 20 20 20 20 20
Joaozinho
200 300 400 400 500 500 500 600 650 650 700 810
4 is equivalent to the number of players, the strings to their respective names and the integers to the scores. After typing them, my (incomplete) code should print the names and scores, but instead it asks for the reading of one more value, which I have no idea what it is.
I have tried to use gets
, scanf
, and now fgets
- considering that the error was in reading the strings - but it did not work.
What has been causing this? Why at the end of the test case does it ask for more?