TOPIC

Wrong Answer 100% (funcionando)

Keny asked 2 years ago

Meu código funciona, porém recebo wrong answer 100%. Já modifiquei algumas vezes a maneira de comparar a string mas continua dando o mesmo erro. Esta é a minha ultima modificação.

#include <stdio.h>
#include <string.h>
int main(){
    char chatr[8];
    int res, i = 0;
    while(i < 10){
        scanf("%s", &chatr);
        if(strcmp (chatr, "esquerda") == 0){
            printf("ingles\n");
        } 
        if(strcmp (chatr, "direita") == 0){
            printf("frances\n");
        } 
        if(strcmp (chatr, "nenhuma") == 0){
            printf("portugues\n");
        } 
        if(strcmp (chatr, "as\0duas") == 0){
            printf("caiu\n");
            return 0;
        }
    }
}

Remember not post solutions. Your post may be reviewed by our moderators.

  • feodorv replied 2 years ago

        char chatr[8];

    Too small buffer size.

    if(strcmp (chatr, "as\0duas") == 0){

    Oh. What do you want by it? \0 denotes the end of a string so the comparison will be with string "as" only. If you want to compare with some string containing the spaces you can use fgets function to read the input or make a small trick:

    if( strcmp( chatr, "as")  ==  0 ){
                scanf( "%s", chatr);
                printf( "caiu\n" );
            }

    And for what return 0 is here?

        while(i < 10){

    Oh, oh. Why 10, why not 10000000? The input should be read untill EOF:

      while( scanf( "%s", chatr) == 1 ){
  • João Lucas S. Mota replied 2 years ago

    Coloque o while fazendo EOF