Translations of this page?:

strcmp

文法:

    #include <cstring>
    int strcmp( const char *文字列1, const char *文字列2 );

strcmp()関数は文字列1文字列2を比較して以下のような値を返します:

返り値 説明
0未満 str1str2よりも小さい
0 str1str2は同一
0より大きい str1str2よりも大きい

サンプル:

     printf( "名前を入れてください: " );
     scanf( "%s", name );
     if( strcmp( name, "Mary" ) == 0 ) {
       printf( "こんにちわ, Dr. Mary!\n" );
     }

もしも文字列1と文字列2を調べてもNULL終端文字が見つからなかった場合には、strcmp()は正しい結果を返しません。似たような関数で、境界チェックを行う、安全なバージョンのstrncmp()関数もあります。

関連トピック: memcmp, strcat, strchr, strcoll, strcpy, strlen, strncmp, strxfrm

 
• • • SitemapRecent changesRSScc