0
#include <stdio.h>
#include <string.h>
#define tam 10

int main()
{
    int N, i;
    char name[tam], name2[tam];
    char name3[] = {"ataque"};
    char name4[] = {"pedra"};
    char name5[] = {"papel"};

    scanf("%d", &N); // Entrada do número de repetições

    for (i = 0; i < N; i++)
    {

        fgets(name, tam, stdin); // Entrada de dados
        fgets(name2, tam, stdin);

        if (strncmp(name, name3, 6) == 0)
        { // Comparação das strings para saber o resultado
            if (strcmp(name, name2) == 0)
                printf("Aniquilicao mutua\n");
            else
                printf("Jogador 1 venceu\n");
        }

        else if (strncmp(name, name4, 5) == 0)
        { // Outra possibilidade
            if (strcmp(name, name2) == 0)
                printf("Sem ganhador\n");
            else if (strncmp(name2, name3, 6) == 0)
                printf("Jogador 2 venceu\n");
            else
                printf("Jogador 1 venceu\n");
        }

        else if (strncmp(name, name5, 5) == 0)
        {
            if (strcmp(name, name2) == 0)
                printf("Ambos venceram\n");
            else
                printf("Jogador 2 venceu\n");
        }
    }

    return 0;
}

I don't know why but the loop isn't working until the end "}". It's reading only the first "fgets" and it ends there. It should read until the last "else if". Can somebody help me, please?

WhozCraig
  • 65,258
  • 11
  • 75
  • 141

0 Answers0