if statement broken!!?????

I must be missing something obvious or the world is broken. I have an if statement that I think should be entered but is not.

Here is a portion of my code

int readResponse(char* Good, char* Error)
{
    static bool keyCharReceived = false;
    static char RxChars[CMPSTRLENGTH];
    uint8_t inChar;
    static int goodChars = 0;
    
    

    if(eusartRxCount > 0){
        //Led1_Toggle();
        inChar = EUSART_Read();
        
        bool keyCharCheck = ~keyCharReceived;
        bool GoodCharCheck = (Good[0] == inChar);
        bool BothCombined = (keyCharCheck && GoodCharCheck);
        
        
        if(Good[0] == inChar && ~keyCharReceived){
            keyCharReceived = true;
            memset(RxChars, NULL, CMPSTRLENGTH); //Need to include #include <string.h>
            goodChars = 0;
            RxChars[goodChars] = inChar;
        }
        else if(Error[0] == inChar && ~keyCharReceived){
            keyCharReceived = true;
            memset(RxChars, NULL, CMPSTRLENGTH); //Need to include #include <string.h>
            goodChars = 0;
            RxChars[goodChars] = inChar;
        }
        else if(keyCharReceived){
            goodChars++;
            RxChars[goodChars] = inChar;
        }

///////////// More here but I don't think it is needed for understanding

Specifically I am talking about the

if(Good[0] == inChar && ~keyCharReceived){

In my variable explorer (using MPLAB forgive me (you guys explain things on my level more)) I see that Good[0] is ‘:’ and inChar is ‘:’. The keyCharReceived is 0. Anyway I single step my program using my debugger from the if in question and I see that instead of entering that first if it enters that first else if (???) Then if I continue single stepping the program it then will enter that second else if (how can it enter both else ifs?)

Why are you using ~ on a bool? Use must use !

MarkT: Why are you using ~ on a bool? Use must use !

Dang! I have been doing a lot in matlab lately which uses ~. Let me change that and see if it fixes everything.

Update I changed all of the ~ to ! but I am still having the other issues.

My BothCombined variable reads as 0x01 but it won't enter if(Good[0] == inChar && !keyCharReceived). Is is entering the next else if, and then the next!!

Thanks for the help!

Another Update.... I have no idea why I was experiencing the problems I was and would still very much like to figure out why buy I rewrote my code and it is now working. On the upside these problems inspired me to rewrite my code and make it better. Here is what I have now

int readResponse2(char* Good123, char* Error)
{
    uint8_t inChar;
    static int goodChars = 0;
    static int errorChars = 0;
    if(eusartRxCount > 0){
        //Led1_Toggle();
        inChar = EUSART_Read();
        uint8_t testchar = Good123[goodChars];
        if(inChar == Good123[goodChars]) goodChars++;
        else goodChars = 0;
        if(goodChars == strlen(Good123)) return 1;
        if(inChar == Error[errorChars]) errorChars++;
        else errorChars = 0;
        if(errorChars == strlen(Error)) return 2;
    }
    return 3;
}

Much better! Just so that there isn't unexplained chunks of code floating around the internet. I am communicating via serial to a device. I send this device a command and will get a response. The response is completely different depending on what I send it. Some responses are good others are errors. I send this function what I consider good and what I consider and error and it tells me which one I got.