在C语言中,可以使用strcmp函数来判断字符串。
strcmp函数接受两个字符串作为参数,并返回一个整数值:
下面是一个例子:
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "Hello";
char str2[] = "World";
int result = strcmp(str1, str2);
if (result == 0) {
printf("两个字符串相等\n");
} else if (result < 0) {
printf("第一个字符串小于第二个字符串\n");
} else {
printf("第一个字符串大于第二个字符串\n");
}
return 0;
}
输出结果为:第一个字符串小于第二个字符串
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: c语言怎么读取寄存器的值