lundi 29 juin 2015

C, if statements and strcmp

I don't understand why it does not pick up on the inputs. It always displays "Invalid Input"... Help!

while(1)
{
    fgets(input, MAX, stdin);
    printf("%s", input);

    if(strcmp(input, "1") == 0)
    {
        add();
    }
    else if(strcmp(input, "2") == 0)
    {
        delete();
    }
    else if(strcmp(input, "3") == 0)
    {
        view();
    }
    else if(strcmp(input, "4") == 0)
    {
        break;
    }
    else
    {
        printf("Invalid Input!\n");
    }
}

Aucun commentaire:

Enregistrer un commentaire