哪位高手帮忙做一道C的题?!拜托了!!急!!

来源:百度知道 编辑:UC知道 时间:2024/06/07 19:46:43
编写函数实现字符串的求长,比大小,拷贝,连接,并测试函数的正确性

#include <stdio.h>

int copy(char *a,char *b)
{ char *from,*to;
for(from=a,to=b;*from!='\0';from++) *to++=*from;
*to='\0';

return 0;
}

int link(char *a,char *b)
{
while(*a!='\0') a++;
for(;*b!='\0';b++) *a++=*b;
*a='\0';

return 0;
}

int compare(char *a,char *b)
{
int i=0,m,n;
char *p,*q,*temp;
for(m=0,p=a;*p!='\0';p++) m++;
for(n=0,q=b;*q!='\0';q++) n++;
temp=m>n?b:a;
while(*temp!='\0')
{
if(*a!=*b)
{
return *a>*b?i:(-i);
break;
}
temp++;a++;b++;i++;
}
if(*a==*b) return 0;

}

int length(char *a)
{
int i;
for(i=0;*a!='\0';i++,a++) ;
return i;
}
void main()
{
char *a="abcD