#include<string.h>
#include<stdio.h>
#include<ctype.h>
char a[101],b[101];
int main (){
int c;
gets(a);
gets(b);
for (int i = 0;i < strlen(a);i ++) {
a[i] = toupper (a[i]);
b[i] = toupper (b[i]);
}
//printf("%s\n%s\n",a,b);
if (strcmp(a,b) > 0) c = 1;
else if (strcmp(a,b) == 0) c = 0;
else c = -1;
printf("%d",c);
return 0;
}
先把两个字符串大小写统一,这里使用 toupper() :
头文件: ctype.h
定义: int toupper (int a); < 换成大写>
int tolower(int a); < 换成小写>
有一点定义不清: 负数在判断时 是 true.