Share this page

# strcmp

String Manipulation Functions

Compares string1 and string2 to determine the alphabetic order.

    int strcmp( constchar *string1, const char *string2 );

string1 | The first string that is compared.
string2 | The second string that is compared.

## Return Values

Returns a value indicating the lexicographical relation between the strings:

Return value | Description
--- | ---
<0 | string1 is less than string2
0 | string1 is the same as string2
>0 | string1 is greater than string2

## Example

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.

Copy code

        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 );

    Example: Output:
    Action.c(17): strcmp: String 1 is greater than string 2
    Action.c(28): stricmp: String 1 is equal to string 2

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: