qfedu-c-level/day11/d11.c

30 lines
573 B
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void strcp(char *dest, char *src)
{
int len = 0;
while (src[len++]) // 计算 src 的长度
;
for (int i = 0; i < len - 1; i++) // len-1 会去掉字符串末尾的'\0'
{
*(dest + i) = *(src + i); // dest[i] = src[i];
}
// dest 原内容多余的部分要清空
while (dest[len - 1])
{
dest[len - 1] = 0;
len++;
}
}
int main()
{
char p[100] = "disen,666,小马,888";
strcp(p, "disen,jack,lucy");
printf("%s\n", p);
return 0;
}