0

構造体ポインタに問題があります....dsp がポインタではなく、InMemory[Idx] がポインタであることを除いて、本質的に同じことを行っている私のコードの 2 つの例を次に示します。ポインタの場合に 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);
4

1 に答える 1

1

コードから、InMemory のメンバー要素を割り当てていません

for (i=0;i<SIZE;i++)
{ 
  // allocate elements here
  InMemory[i]->filename = malloc(....)
  // other allocations
}

// now use memcpy
于 2012-11-28T01:19:24.077 に答える