Strstr() failing!

I can’t believe it, but it seems that the strstr() function is giving me erroneous results… To prove the point, I have written this piece of test code:

/*
   strstr-fail.in0
   
   Testing strstr() operation
*/

/*

2017-11-16 
- Created

*/
   

bool bOnceOff = false;
char szSrc[64];

void setup() {
    
    Serial.begin();
}

void loop() 
{
    const char * psz2;
     
    if (!bOnceOff)
    {
        bOnceOff = true;
        
        Serial.println("Tests");
        
        strcpy(szSrc, "0123456789012345678901234567890123456789");
        
        if (strstr(szSrc,psz2="0123456789012345678901234567890123456789") == NULL);
        {
            Serial.printf("FAIL <%s> :: <%s>\r\n", szSrc, psz2);
        }
        
        if (strstr(szSrc,psz2="01234567890123456789") == NULL);
        {
            Serial.printf("FAIL <%s> :: <%s>\r\n", szSrc, psz2);
        }

        if (strstr(szSrc,psz2="012345") == NULL);
        {
            Serial.printf("FAIL <%s> :: <%s>\r\n", szSrc, psz2);
        }
        

        strcpy(szSrc, "0123456789");
        
        if (strstr(szSrc,psz2="0123456789") == NULL);
        {
            Serial.printf("FAIL <%s> :: <%s>\r\n", szSrc, psz2);
        }

        if (strstr(szSrc,psz2="01234") == NULL);
        {
            Serial.printf("FAIL <%s> :: <%s>\r\n", szSrc, psz2);
        }

    }


}

Here is the output:

Tests
FAIL <0123456789012345678901234567890123456789> :: <0123456789012345678901234567890123456789>
FAIL <0123456789012345678901234567890123456789> :: <01234567890123456789>
FAIL <0123456789012345678901234567890123456789> :: <012345>
FAIL <0123456789> :: <0123456789>
FAIL <0123456789> :: <01234>

Anyone have the same problem or clue as to what is going on with this most basic of functions?

Case closed…

Note the pesky… “;” at the end of the if statement. Going blind…

4 Likes

Thanks for posting your solution!