- #include <stdio.h>
- #include <string.h>
- int fun(char *a,char *b)
- {
- int i = 0,j = 0;
- while(a[i]&&b[j])
- {
- if(a[i]-b[j]>0)
- return 1;
- else if(a[i]-b[j]<0)
- return -1;
- i++,j++;
- }
- if(strlen(a)==i&&strlen(b)==j)
- return 0;
- else if(strlen(a)==i)
- {
- return -1;
- }
- else
- return 1;
- }
- int main()
- {
- char a[100];
- char b[100];
- printf("\\n");
- printf("*******比较两个字符串的大小:*******\\n");
- printf("\\n");
- printf("输入第一个字符串:");
- scanf("%s",a);
- printf("输入第二个字符串:");
- scanf("%s",b);
- printf("%d\\n",fun(a,b));
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/0508201513343.html
来源: http://www.codesnippet.cn/detail/0508201513343.html