可以使用strcmp()函数来比较两个字符串。该函数返回的值是一个整数,表示字符串1与字符串2的大小关系。如果字符串1小于字符串2,则返回一个负数;如果字符串1大于字符串2,则返回一个正数;如果两个字符串相等,则返回0。根据这个返回值,我们可以判断出两个月份字符串的大小关系。
代码示例:
#include
#include
int main() {
char month1[10] = "feb";
char month2[10] = "jan";
int result;
result = strcmp(month1, month2);
if(result > 0) {
printf("%s is greater than %s\n", month1, month2);
}
else if(result < 0) {
printf("%s is less than %s\n", month1, month2);
}
else {
printf("%s is equal to %s\n", month1, month2);
}
return 0;
}
输出结果为:feb is greater than jan