char *strdup1(const char *strSrc)
{
if (strSrc != NULL)
{
int len = 0;
const char *start = strSrc;
while (*strSrc++ != '\0')
{
++len;
}
char *address = (char *)malloc(len +1);
assert(address != NULL);
while ((*address++ = *start++) != '\0');//这个最后还会多加1
return address-(len+1);//这里-1,在减去整个长度,就返回到0下标了
}
return NULL;
}将字符串拷贝到新位置
最新推荐文章于 2022-12-05 11:51:50 发布
2435

被折叠的 条评论
为什么被折叠?



