I have this code, however I am unsure of how to access the struct pointers after passing the struct by reference into a function, the program crashes on this line, accessing the pointers doesnt work.
scanf("(%lf,%lf)",polygon->xvals[i],polygon->yvals[i]);
FIXED CODE, thanks to all who answered
struct Polygon{
double *xvals, *yvals;
int numverts;
};
typedef struct Polygon pol;
pol getpoly(pol *polygon);
int main(){
pol polygon;
getpoly(&polygon);
}
pol getpoly(pol *polygon){
polygon->xvals = (double * )malloc(sizeof(double)*polygon->numverts);
polygon->yvals = (double * )malloc(sizeof(double)*polygon->numverts);
check=0;
int i;
for(i=0;i<10;i++){
while(check !=2 ){
cout<<"enter vertices "<<i<<" (x,y)\n";
check = scanf("(%lf,%lf)",&polygon->xvals[i],&polygon->yvals[i]);
_flushall();
}
check=0;
}
polygon->xvals[polygon->numverts-1] = polygon->xvals[0];
polygon->yvals[polygon->numverts-1] = polygon->yvals[0];
return *polygon;
}
returninmainof course).cout <<?