C &引用;无法转换为指针类型";通过指针访问结构

C &引用;无法转换为指针类型";通过指针访问结构,c,pointers,struct,C,Pointers,Struct,您缺少一个符号(&): (我去掉了不必要的石膏)。你想要这个: firstfunction(&onedata->c, &twodata.c,2); ^ 您刚刚忘记了&操作符 顺便说一句:这里没有必要强制转换到(void*)。作为旁注,通常认为执行void main()而不是int main()不需要就使用void*是不好的形式。并且不要在void*之间进行强制转换。 struct one { char a; char b;

您缺少一个符号(
&
):

(我去掉了不必要的石膏)。

你想要这个:

 firstfunction(&onedata->c, &twodata.c,2);
               ^
您刚刚忘记了
&
操作符


顺便说一句:这里没有必要强制转换到
(void*)

作为旁注,通常认为执行
void main()
而不是
int main()
不需要就使用
void*
是不好的形式。并且不要在
void*
之间进行强制转换。
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);
}
 firstfunction(&onedata->c, &twodata.c,2);
               ^
void secondfunction(struct two *onedata)
{
  struct two twodata;
  firstfunction(&onedata->c, &twodata.c, 2);
}