概述
模拟实现的字符串处理函数:
strlen,strcat,strncat,strchr,strrchr,strcpy,strncpy
1.strlen,求字符串的长度,不算‘/0’
size_t mystrlen(const char *string)
{
const char *p = string;
while (*p++)
{}
return(p - string - 1);
}
2.strcat,拼接字符串
char *mystrcat(char *dest, const char *source)//两个字符串拼接
{
char *address = dest;
assert((*dest != NULL) && (*source != NULL));
while (*dest++)
{}
while (*(dest++) = *(source++))
{}
return address;
}
3.strncat,拼接字符串,把第二串字符串前count字符拼接到第一个字符串后面
char *mystrncat(char *dest, const char* source,size_t count)//把2字符串前count个接到1字符串后面
{
char *address = dest;
assert((*dest != NULL) && (*source != NULL));
while (*dest != '