strcpy,strcat,strlen,strcmp的实现(欢迎拍砖)
int strlenC(const char *str)
{
assert(str!=NULL);
int i = 0;
while(str[i]!='\0')
{
i++;
}
return i;
{
assert(des!=NULL&&src!=NULL);
char * desCpy = des;
while((*desCpy++=*src++)!=NULL);
return des;
{
assert(des!=NULL&&src!=NULL);
char *desCpy = des;
while(*desCpy!='\0')
++desCpy;
while((*desCpy++=*src++)!='\0');
return des;
{
int ret=0;
assert(des!=NULL&&src!=NULL);
while((ret=*(unsigned char *)des-*(unsigned char *)src)==0&&*src!='\0')
{
++des;
++src;
}
if(ret>0)
{
return 1;
}
else if(ret<0)
{
return -1;
}
else
{
return 0;
}
}
{
assert(str!=NULL);
int i = 0;
while(str[i]!='\0')
{
i++;
}
return i;
}
char * strcpyC(char *des,const char * src)
{
assert(des!=NULL&&src!=NULL);
char * desCpy = des;
while((*desCpy++=*src++)!=NULL);
return des;
}
char * strcatC(char *des,const char * src)
{
assert(des!=NULL&&src!=NULL);
char *desCpy = des;
while(*desCpy!='\0')
++desCpy;
while((*desCpy++=*src++)!='\0');
return des;
}
int strcmpC(const char *des,const char *src)
{
int ret=0;
assert(des!=NULL&&src!=NULL);
while((ret=*(unsigned char *)des-*(unsigned char *)src)==0&&*src!='\0')
{
++des;
++src;
}
if(ret>0)
{
return 1;
}
else if(ret<0)
{
return -1;
}
else
{
return 0;
}
}