One major problem is here:
char myLookUpValue = "y";
The expression "y"
is a string literal and has type "2-element array of char
" with the contents {'y', 0}
. To define a character literal, use single quotes instead:
char myLookupValue = 'y';
Except when it is the operand of the sizeof
or unary &
operators, or is a string literal being used to initialize another array in a declaration, an expression of type "N-element array of T
" will be converted ("decay") to an expression of type "pointer to T
", and the value of the expression will be the address of the first element of the array.
In your code, the expression"y"
is not the operand of the sizeof
or unary &
operators, and while it's being used to initialize something in a declaration, that something isn't an array of char
, so it's converted to a pointer type and its value is the address of first letter of the string in storage. That address value is then converted to type char
and assigned to myLookupValue
; the result is most likely not any of 'w'
, 'x'
, 'y'
, or 'z'
. so the comparison fails.