3

I'm having a problem with gets() working. The thing is it should be working with just a warning from vars I am not using but the first gets just skips to the second.

int addClube(char *fileName)
{

        char qClube2[100], qClubeSimple[100], qEstadio[100], qCompleto[500],qAcronimo[100];
        int option=0;

        printf("\n  Indique o nome completo do clube:\n  (sem acentos)\n  ");
        gets(qClube2);

        printf("\n  Indique o nome simplificado do clube:\n  (sem acentos)\n  ");
        gets(qClubeSimple);

        printf("\n  Indique o acronimo do clube:\n  ");
        scanf("%s",qAcronimo);

        printf("\n  Indique o nome do estadio:\n  ");
        gets(qEstadio);

        return option;
}

The output I get when the function starts:

Indique o nome completo do clube:
(sem acentos)

Indique o nome simplificado do clube:
(sem acentos)    

Once again thanks in advance for the help an if you more info just tell me.

Rafael Botas
  • 125
  • 1
  • 1
  • 9

2 Answers2

1

If you need to clear the input stream, fflush(stdin) will not do the job. It is my understanding that it works on Windows, but most other systems (UNIX, Linux) it is undefined behavior.

I wrote this on the fly, so it may or may not work, but essentially you need to discard all data you don't want. The following discards a line from the input buffer.

void clearinline(void)
{
    int c;
    do {
        c = getchar();
    } while(c != '\n' && c != EOF)
}
PC Luddite
  • 5,883
  • 6
  • 23
  • 39
-3

Try Using fflush(stdin); after all the gets() Check This; Also, why are u using this option var for ?

Joe Kerr
  • 34
  • 9