How to compare a char?
cmd
is a char type but "e"
is a string not a char type,you should write like this if(cmd == 'e')
First of, in C single quotes are char literals, and double quotes are string literals. Thus, 'C' and "C" are not the same thing.
To do string comparisons, use strcmp.
const char* str = "abc";
if (strcmp ("abc", str) == 0) {
printf("strings match\n");
}
To do char comparisons, use the equality operator.
char c = 'a';
if ('a' == c) {
printf("characters match\n");
}