Translations of this page?:

strcmp

语法:

    #include <cstring>
    int strcmp( const char *str1, const char *str2 );

strcmp()比较 str1 和 str2, 然后返回:

返回值 解释
小于零 str1 小于 str2
等于零 str1 等于 str2
大于零 str1 大于 str2

例如:

     printf( "Enter your name: " );
     scanf( "%s", name );
     if( strcmp( name, "Mary" ) == 0 ) {
       printf( "Hello, Dr. Mary!\n" );
     }

注意如果 str1 或者 str2 丢失空终止符,那么 strcmp() 可能产生不正确的结果。一个类似(更安全)的包含显式边界检查的函数,参见 strncmp()。

相关主题: memcmp, strcat, strchr, strcoll, strcpy, strlen, strncmp, strxfrm

 
• • • SitemapRecent changesRSScc