此特定代码块的最后一行产生错误“需要左值作为赋值的左操作数”。困惑在于为什么最后一行会引发此错误,而倒数第二行则不会。
int p2 = 0;
spage = find(in.startpage);
spage->noutgoing++;
spage->outgoing = (struct webpage *)realloc((spage->outgoing),((spage->noutgoing)*sizeof(struct webpage)));
epage = find(in.endpage);
epage->nincoming++;
epage->incoming = (struct webpage *)realloc((epage->incoming),((epage->nincoming)*sizeof(struct webpage)));
position = ((epage->nincoming));
&(epage->incoming[0]) = spage;
&(epage->incoming[p2]) = spage;
其中spage
,epage
是下面定义的结构:
struct webpage {
char name; /* name of page */
struct webpage *outgoing; //array of pointers pointing to outgoing webpages
struct webpage *incoming ; //array of pointers pointing to incoming webpages
int noutgoing;
int nincoming;
};
并且该函数find
返回一个指向 a 的指针struct webpage
。
通过更改结构outgoing
和incoming
双指针并将最后一行更改为(epage->incoming[p2]) = spage;
.
仍然不知道为什么会发生错误...