c语言中怎样用指针复制字符串
在C语言中,可使用指针来复制字符串。可使用strcpy函数还是自定义的函数来实现。
#include <stdio.h>
#include <string.h>
int main() {
char str1[20] = "Hello";
char str2[20];
strcpy(str2, str1); // 使用strcpy函数将str1复制到str2
printf("str1: %s
", str1);
printf("str2: %s
", str2);
return 0;
}
#include <stdio.h>
void stringCopy(char *dest, const char *src) {
while (*src != '