Comparing Characters?

I have a character array set up and I need to see if a specific character in the array is a certain letter. I have tried:
 
if (code[0]=="E") cout<<"1";


That didn't work, even though "E" is exactly what is in that slot of the character array. I did not find any commands for comparing single characters by searching this site.
You should use single quote for that:
'E' is the character value of the letter E "E" is a pointer to a character array containing 'E' and '\0'
Last edited on
Double quotes are used for strings, single quotes are used for characters.

Try

if( code[0] == 'E' ) //...

After trying that, I get the following error from the compiler:
ISO C++ forbids comparison between pointer and integer

edit: I think I found my problem... code is a two-dimensional array.
Last edited on
Yes, that would do it.

if( code[0][0] == 'E' ) //

assuming code is an array of C-style strings.

Topic archived. No new replies allowed.