用c语言编写 按字符顺序比较两个字符串s、t大小,如果s大于t,则返回正值,等于返回0,小于则返回负值

[复制链接]
查看11 | 回复2 | 2011-5-6 12:26:32 | 显示全部楼层 |阅读模式
#include
sub (char *s,char *t)
{for (;*s==*t;)
if (*s=='\0')return 0;
return (*s-*t);
}
如何修改?

回复

使用道具 举报

千问 | 2011-5-6 12:26:32 | 显示全部楼层
#include#includevoid main() { unsigned char src[200]; unsigned char dst[200]; int a,b,i; int ret = 0; printf("Input string 1:"); scanf("%s",src); printf("Input string 2:"); scanf("%s",dst); a=strlen(src); b=strlen(dst); if(a>b) ret=1; else if(a<b) ret=-1; else { for(i=0;i<a;i++) {
if
回复

使用道具 举报

千问 | 2011-5-6 12:26:32 | 显示全部楼层
sub (char *s,char *t){for (;*s==*t;s++,t++)
/*加个地址偏移 */if (*s=='\0')return 0;return (*s-*t);}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行