【发布时间】:2021-08-12 03:43:58
【问题描述】:
我做了一个strcpy() 函数
在 C 中,我将单词从一个数组复制到另一个数组,而不仅仅是字母,但是当我运行它时,我遇到了 Segmentation fault 该怎么办?
#include <stdio.h>
void strcpy1(char *dest[], char source[])
{
while ((*dest++ = *source++));
}
int main()
{
char source[3][20] = { "I", "made", "this" };
char dest[3][20];
strcpy1(&dest, source);
//printing destination array contents
for (int i = 0; i < 3; i++) {
printf("%s\n", dest[i][20]);
}
return 0;
}
【问题讨论】:
标签: c string segmentation-fault char strcpy