#include <stdio.h>
char* fun(char* s, char* t)//不使用库函数strcmp()求字符串长度
{
int s1 = 0;
int t1 = 0;
char* s2 = s;
char* t2 = t;
while (*s2 != '\0')//计算第一个字符串长度
{
s1++;
s2++;
}
while (*t2 != '\0')//计算第二个字符串长度
{
t1++;
t2++;
}
if (s1 >= t1)//如果第一个长或相等 输出第一个字符串
return s;
else
return t;//否则输出第二个
}
main()
{
char a[20], b[20];
printf("请输入第一个字符串:");
gets(a);
printf("请输入第二个字符串:");
gets(b);
printf("%s\n", fun(a, b));
}
不使用库函数strcmp()求字符串长度,比大小
最新推荐文章于 2024-05-13 21:57:53 发布