总结一下C里面常用的字符串函数的实现代码~
//strlen
unsigned int strlenght(const char *src)
{
unsigned int len = 0;
while(*src++)
{
len++;
}
return len;
}
//strcat
char* strlink(char* dest,const char* src)
{
char *temp = dest;
while(*dest++);
*dest--;//移动到\0前一个元素处
while(*dest++=*src++);
return temp;
}
//strcpy
char* strcopy(char* dest,const char* src)
{
char *temp = dest;
while(*dest++ = *src++);
return temp;
}
//strcmp
int strcompare(const char* src1,const char*src2)
{
int x=0;
While(!(x = *src1-*src2) && *src1)
{
src1++;
src2++;
}
if(x>0)
x = 1;
if(x<0)
x = -1;
return x;
}