Originally Posted by
Eman
Hey I maybe a noob but maybe I can help with this one.
char answer=="a"
you are comparing a string when it should be 'a'
a string is an array of characters, and when you store a string - they are divided into characters
so if i had
char answer[6] = "Hello" ;
it will be like this in memory
'H' 'e' 'l' 'l' 'o' '\0'
Notice that although the length of hello is 5 characters long, I am declaring the variable answer as having 6 elements, because a string of char type in C/C++ must be terminated by a null character.
so when you did
char answer[0] ="a"
number one that is redundant.
Why do that, when you can simply do char
answer = 'a' ?
also when you initialize
char answer[0]="a"
I am surprised that even compiled..the compiler should have told you to declare at least one element, I know this without compiling it, because I did the same thing last year ;)
If you had declared more than one element for answer, then your if statement should have worked.
strcmp should have worked as well
Since others have provided a code for strcmp. I wouldn't
but I hope my explanation on how strings are stored in memory helped :D.