strcmp
语法:
1 2 3 |
? #include <string.h> ? int strcmp( const char *str1, const char *str2 ); |
功能:比较字符串str1 and str2, 返回值如下:
返回值????????????????????? 解释
less than 0?????????? str1 is less than str2
equal to 0???????????? str1 is equal to str2
greater than 0???? str1 is greater than str2
例如:
1 2 3 4 5 6 7 |
??? printf( "Enter your name: " ); ??? scanf( "%s", name ); ??? if( strcmp( name, "Mary" ) == 0 ) ????? printf( "Hello, Dr. Mary!\n" ); |