// 为了准备一个面试,重新写了一些STRIGN的函数,
int StrCmp(const char * dst, const char * src)
{
int ret = 0 ;
while (!(ret = *dst - *src) && *dst)
{
src++;
dst++;
}
if (ret < 0 )
ret = -1 ;
else if (ret > 0 )
ret = 1 ;
return ret;
}
char* StrCpy(char * dst, const char * src, int count)
{
char* pTemp = dst;
while (count--)
{
*pTemp++ = *src++;
}
return dst;
}
char* StrCpy(char * dst, const char * src)
{
char* pTemp = dst;
while (*pTemp++ = *src++);
return dst;
}
char* StrTrim(char* s)
{
char* pDst = s;
while(1)
{
if (*pDst == ' ' || *pDst == '\t' || *pDst == '\n')
{
pDst++;
}
else
{
break;
}
}
char* p = pDst;
while(*p++);
p -= 2;
while(1)
{
if (*p == ' ' || *p == '\t' || *p == '\n')
{
p--;
}
else
{
break;
}
}
*(p+1) = '\0';
return pDst;
}
int StrLen(const char* str)
{
int len = 0;
while(*str++)
{
len++;
}
return len;
}
char* StrCat(char* dst, const char* src)
{
char *pTemp = dst;
while (*pTemp++);
pTemp--;
while (*pTemp++ = *src++);
return dst;
}