我正在尝试使用指针编写自己的strcpy函数,但在运行时出现错误。
void str_cpy(char **destination, const char *source) {
// char *s1 = *destination;
while (*source != '\0') {
**destination++ = *source++; //Get an error here
}
**destination = '\0';
}
我按照以下方式调用函数:
char *str = NULL;
str_cpy(&str, "String");
这个可以吗?
谢谢!