+ 1
How to compare char using if condition in c.
#include <stdio.h> int main() { char ans1='c',a; printf("father of c?\n a.baa \n c.Dennis\n"); scanf("%s",&a); if(a==ans1) { printf("5"); } else { printf("6"); } return 0; }
2 Réponses
+ 5
You're doing it in the right way but your input is expecting a string instead of a char, just change it like so:
scanf("%c",&a);
And you're ready to go!
0
thank you maz