TEMA

Linguagem C - Wrong answer 15%

vitorbisterso preguntado 3 years ago

Meu código em C está assim:

Pregunta resuelta. Código eliminado.

Alguém tem alguma ideia de como resolver?

Este tema fue resuelto y no puede recibir nuevas respuestas.

  • feodorv respondido 3 years ago

    Why line has 101 bytes in size, but in fgets you use only 100 bytes? So you read only first 99 bytes of 100-characters input string, and one byte fgets reserves for '\0'.

      char line[101];
    ...
        fgets( line, sizeof(line), stdin);

    Why 101? 100+1? Why be so greedy? We can provide more memory:

      char line[128];
    ...
        fgets( line, sizeof(line), stdin);
  • vitorbisterso respondido 3 years ago

    Thanks FEODORV, I've implemented your suggested changes and it worked!