I am learning c. I have a question. Why doesn\'t my program work?
#include
#include
#include
char cmd;
void
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");
}
cmd
is a char type but "e"
is a string not a char type,you should write like this if(cmd == 'e')