通过指针访问结构“无法转换为指针类型”

Art*_*gda 0 c struct pointers

gcc -g -O2    struct.c   -o struct
struct.c: In function ‘secondfunction’:
struct.c:19:2: error: cannot convert to a pointer type
  firstfunction((void *)onedata->c,(void *)&twodata.c,2);
  ^~~~~~~~~~~~~
<builtin>: recipe for target 'struct' failed
make: *** [struct] Error 1
Run Code Online (Sandbox Code Playgroud)

我试图通过memcpy将struct的内容复制到另一个struct时使用指针。但是,当我将指向该结构的指针转换为函数时,无法将其强制转换为空白。

struct one {
    char a;
    char b;
};

struct two {
    struct one c;
    struct one d;
};

void firstfunction(void *source, void *dest, int size)
{
    //memcpy(dest,source,size)
}

void secondfunction(struct two *onedata)
{
    struct two twodata;
    firstfunction((void *)onedata->c,(void *)&twodata.c,2);
}

void main()
{
    struct two onedata;
    secondfunction(&onedata);
}
Run Code Online (Sandbox Code Playgroud)

usr*_*usr 5

您缺少与号(&):

 firstfunction(&onedata->c, &twodata.c,2);
               ^
Run Code Online (Sandbox Code Playgroud)

(我删除了不必要的演员表)。