+ 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; }

30th Aug 2021, 3:35 PM
Shubham Rampurkar
Shubham Rampurkar - avatar
2 Respuestas
+ 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!
30th Aug 2021, 3:39 PM
Maz
Maz - avatar
0
thank you maz
30th Aug 2021, 3:49 PM
Shubham Rampurkar
Shubham Rampurkar - avatar