I have to make a program that allows the user to input characters then prints its decimal character code. One of the characters is ' but when I go to check for this character it says it is missing the terminating ' character.
case ''':
printf("039");
break;
How do I check for ' as a charcter?
CodePudding user response:
You can use an escape sequence.
case '\'':
printf("039");
break;
CodePudding user response:
You should use a backslash(\
) before using '
. Because '
is a special character.
So, you should use as follows,
case '\'':
printf("039");
break;
CodePudding user response:
You should use the \
character before the ‘
. This is because in c the character ’
is used as a opener or closer for a character value. This means you need to tell the compiler to treat it as a normal character by adding \
before it. The same thing goes for “
and \
(if you want to use a backslash in a string instead of the purposes listed above.)
Using this method your code should look like this:
case ‘\’’: printf(“039”); break;