char *mystrchr(char *src, int letter)
{
assert(src != NULL);
while((*src != letter)&&(*src))
src++;
if(*src=='\0')
return NULL;
return (src);
}
char *mystrcat(char *des,const char *src)
{
assert((des != NULL) && (src !=NULL));
char *address = (char *)malloc(strlen(des)+strlen(src)+1);
char *p_address = address;
while((*address = *des) != '\0')
{
++address;
++des;
}
while((*address++ = *src++) != '\0');//已经赋值'\0'再判断!='\0'
return p_address;
}
void *my_memcpy(void *Des, const void *Src, int len)
{
assert((Des != NULL) && (Src != NULL));
void *address = Des;
while(len--)
*(char *)Des++ = *(char *)Src++;
return address;
}
int strcmp(const char *s, const char *t)
{
assert(s != NULL && t != NULL);
while (*s && *t &&( *s++ == *t++));
return (*s - *t);
}
char *strcpy(char *strDes, const char *strSrc)
{
assert((strDes != NULL) && (strSrc != NULL));
char *address = strDes;
while ((*strDes ++ = *strSrc ++) != '\0');
return address;
}
几个笔试必备string函数(已经调过)
最新推荐文章于 2024-06-28 00:25:59 发布