主页
C 语言
C 字符串 strncmp() 函数
demo_ref_string_strncmp
运行 ❯
×
更改方向
保存代码
更改主题
#include
#include
int main() { char myStr1[] = "ABCD"; char myStr2[] = "ABCE"; int cmp = strncmp(myStr1, myStr2, 3); if (cmp > 0) { printf("%s is greater than %s\n", myStr1, myStr2); } else if (cmp < 0) { printf("%s is greater than %s\n", myStr2, myStr1); } else { printf("%s is equal to %s\n", myStr1, myStr2); } return 0; }
ABCD is equal to ABCE