我搜索了整个 StackOverflow,但找不到我想要做的事情。我想将指针项目复制到指针 COPYTO。然后可以调用 COPYTO->x。
#include <stdio.h>
typedef struct JustArray {
char x[30];
} JustArray;
int main()
{
JustArray *Items, *COPYTO;
char d[10] = "Test";
Items = malloc(sizeof(Items));
COPYTO = malloc(sizeof(COPYTO));
strcpy(&Items->x,d);
memmove(©TO, Items, sizeof(JustArray));
printf("Pointer: %p\n", &d);
printf("Address: %u\n",&d);
printf("Value: %s\n", Items->x);
printf("Value: %s\n", COPYTO->x);
return 0;
}
该程序编译但不会运行。它有一个弹出窗口说:访问冲突读取位置0xabababab。
我来自 C#,发现 C 非常难以理解......