Example: strcmp

The following example compares two strings, string1 and string2, which are identical except for the word "quick" which is lowercase in string1 and uppercase in string2. strcmp, which is case-sensitive, returns an unequal comparison.

    int result;
    char tmp[20];
    char string1[] = "The quick brown dog jumps over the lazy fox";
    char string2[] = "The QUICK brown dog jumps over the lazy fox";
// Case-sensitive comparison 
    result = strcmp( string1, string2); 
    if(result > 0)
        strcpy(tmp, "greater than");
    else if(result < 0)
        strcpy(tmp, "less than");
    else
        strcpy(tmp, "equal to");
    lr_output_message ("strcmp: String 1 is %s string 2", tmp);
// Case-insensitive comparison
    result = stricmp(string1, string2 );  
    if( result > 0 )
        strcpy( tmp, "greater than" );
    else if( result < 0 )
        strcpy( tmp, "less than" ); 
    else
        strcpy( tmp, "equal to" );
    lr_output_message( "stricmp: String 1 is %s string 2", tmp );
Output:
Action.c(17): strcmp: String 1 is greater than string 2
Action.c(28): stricmp: String 1 is equal to string 2