我想在结构数组中设置结构数组。为此我创建了一个函数。我怎么试试它,我无法做到这一点。将结构数组作为参数传递给函数
struct polygon {
struct point polygonVertexes[100];
};
struct polygon polygons[800];
int polygonCounter = 0;
int setPolygonQuardinates(struct point polygonVertexes[]) {
memcpy(polygons[polygonCounter].polygonVertexes, polygonVertexes,4);
}
int main(){
struct point polygonPoints[100] = {points[point1], points[point2], points[point3], points[point4]};
setPolygonQuardinates(polygonPoints);
drawpolygon();
}
void drawpolygon() {
for (int i = 0; polygons[i].polygonVertexes != NULL; i++) {
glBegin(GL_POLYGON);
for (int j= 0; polygons[i].polygonVertexes[j].x != NULL; j++) {
struct point pointToDraw = {polygons[i].polygonVertexes[j].x, polygons[i].polygonVertexes[j].y};
glVertex2i(pointToDraw.x, pointToDraw.y);
}
glEnd();
}
}
当我运行此我得到以下错误
Segmentation fault; core dumped; real time
“我无法做到这一点是什么意思?” – OldProgrammer
此代码的任何特定错误? – Gaurav
对不起的英语感到抱歉。我的意思是我无法将polygonPoints数组复制到polygon结构的polygonVertexes成员中。 setPolygonQuardinates函数执行后,polygonVertexes成员具有垃圾值。 –