strncmp
int strncmp( const char *str1, const char *str2, size_t count )
先頭count文字だけ文字列str1と文字列str2を比較する。
戻り値は、string1 と string2 の部分文字列の関係を示す。
もし文字列strの先頭3文字が"abc"なら処理をする
先頭count文字だけ文字列str1と文字列str2を比較する。
戻り値は、string1 と string2 の部分文字列の関係を示す。
戻り値 | 説明 |
< 0 | string1 の部分文字列は string2 の部分文字列より小さい |
0 | string1 の部分文字列は string2 の部分文字列と同じ |
> 0 | string1 の部分文字列は string2 の部分文字列より大きい |
if ( strncmp( str, "abc", 3 ) == 0 ) {
・・・
}
もし文字列strの先頭3文字が"abc"なら処理をする
Comments