dimanche 28 juillet 2019

How can I use the if statement on this char in C? [duplicate]

This question already has an answer here:

I am trying to make a simple calculator program in C using functions and I am trying to use the if statement to determine the user inputted char string.

The function works as intended, I tried to make it as 3 and 4 sized char and it did not work.

int a, b, ans;
char *userChoice;
while (1)
{
    sf("%d %d %s", &a, &b, &userChoice);
    if(userChoice == "add")
    {
        ans = add(a, b);
        pf("%d", ans);
    }
    else if (userChoice == "sub")
    {
        ans = sub(a, b);
        pf("%d", ans);
    }
}

No error messages, and no output. Same with no while loop.

Aucun commentaire:

Enregistrer un commentaire