比较两个字符串的大小 strcmp

Run Settings
LanguageC
Language Version
Run Command
#include <stdio.h> #include <string.h> int main() { char str1[] = "hello A"; char str2[] = "hello a"; char str3[] = "hello"; void strCompare(char *, char *); // 函数原型声明 strCompare(str1, str2); // 比较字符串1和字符串2 strCompare(str1, str3); // 比较字符串1和字符串3 return 0; } void strCompare(char *s1, char *s2) { int res = strcmp(s1, s2); if (res > 0) printf("字符串 %s 比 %s 大\n", s1, s2); else if (res < 0) printf("字符串 %s 比 %s 小\n", s1, s2); else printf("字符串 %s 与 %s 相等\n", s1, s2); }
Editor Settings
Theme
Key bindings
Full width
Lines