Comparing user-inputted characters in C

Viewed 150392

The following code snippets are from a C program.

The user enters Y or N.

char *answer = '\0';

scanf (" %c", answer);

if (*answer == ('Y' || 'y'))
    // do work

I can't figure out why this if statement doesn't evaluate to true.

I checked for the y or n input with a printf and it is there, so I know I'm getting the user input. Also when I replace the the condition of the if statement with 1 (making it true), it evaluates properly.

4 Answers
Related