我在使用结构指针时遇到麻烦。...在我的代码中有两个示例在本质上做同样的事情,除了dsp不是指针,而InMemory [Idx]是指针,在指针情况下如何使用memcpy?
my_struct* InMemory[SIZE]
//works prints: tmp3:local_file (file name)
memcpy(dsp.result.list[i].owner_name,req.file_name,256);
char tmp3[256];
memcpy(tmp3,dsp.result.list[i].owner_name,256);
printf("tmp3:%s\n",tmp3);
//doesn't work, prints: tmp:_____<---nothing! ??
//I am trying to copy the result from above into a field of the struct pointer array
char tmp2[256];
memcpy(InMemory[Idx]->filename,dsp.result.list[i].owner_name,256);
memcpy(tmp2,InMemory[Idx]->filename,256);
printf("tmp:%s\n",tmp2);
最佳答案
从您的代码,您尚未分配内存中的成员元素
关于c - memcpy-int指向c中的结构指针的字段,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13596077/