Middleware, development tools, realtime operating system
software and services for superior embedded design


Home
QNX Community Resources
Developer Support
QNX Documentation Library
QNX Developer Support

QNX Developer Support

QNX Software Systems
Developer Resources
Blogs
Board support packages
Foundry27 projects
Forums
Hardware support listing
Online video tutorials
Product documentation
Technical Articles

[Previous] [Contents] [Index] [Next]

strcmp()

Compare two strings

Synopsis:

#include <string.h>

int strcmp( const char* s1, 
            const char* s2 );

Arguments:

s1, s2
The strings that you want to compare.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The strcmp() function compares the string pointed to by s1 to the string pointed to by s2.

Returns:

< 0
s1 is less than s2.
0
s1 is equal to s2.
> 0
s1 is greater than s2.

Examples:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main( void )
{
    printf( "%d\n", strcmp( "abcdef", "abcdef" ) );
    printf( "%d\n", strcmp( "abcdef", "abc" ) );
    printf( "%d\n", strcmp( "abc", "abcdef" ) );
    printf( "%d\n", strcmp( "abcdef", "mnopqr" ) );
    printf( "%d\n", strcmp( "mnopqr", "abcdef" ) );

    return EXIT_SUCCESS;
}

produces the output:

0
1
-1
-1
1

Classification:

ANSI, POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes

See also:

strcasecmp(), strcmpi(), strcoll(), stricmp(), strncasecmp(), strncmp(), strnicmp(), wcscmp(), wcscoll(), wcsncmp()


[Previous] [Contents] [Index] [Next]