全部博文(160)
分类: C/C++
2014-11-04 23:47:41
// 方法strcat
char *strcat(char *strDest, const char *strSrc)
{
assert((strDest != NULL) && (strSrc != NULL));
char *address = strDest;
while(*strDest)
strDest ++;
while((*strDest++ = *strSrc++) != '\0')
NULL;
return address;
}
// 方法strncat
char *strncat(char *strDest, const char *strSrc, size_t count)
{
assert((strDest != NULL) && (strSrc != NULL));
char *address = strDest;
while(*strDest)
strDest ++;
while (count --)
if ((*strDest++ = *strSrc++) == '\0')
return address;
*strDest = '\0';
return address;
}
// 方法strcpy
char *strcpy(char *strDest, const char *strSrc)
{
assert((strDest != NULL) && (strSrc != NULL));
char *address = strDest;
while((*strDest++ = *strSrc++) != '\0')
NULL;
return address;
}
// 方法strncpy
char *strcpy(char *strDest, const char *strSrc, size_t count)
{
assert((strDest != NULL) && (strSrc != NULL));
char *address = strDest;
while (count && ((*strDest++ = *strSrc++) != '\0'))
count --;
if (count)
while(--count)
*strDest++ = '\0';
return address;
}
// 方法strlen
int strlen(const char *s)
{
assert( s != NULL);
char *p = s;
while(*p != '\0')
p++;
return p - s;
}
// 方法strcmp
int strcmp(const char *src, const char *dst)
{
int ret = 0;
while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst)
++src, ++dst;
if ( ret < 0 )
ret = -1 ;
else if ( ret > 0 )
ret = 1 ;
return( ret );
}