I'm figuring out structs in c and I'm not sure why this is not returning with values. I know that when you pass a function an array, and add values, the values are in the array after the function. Is this true for structs as well? Below is a simplified version of my code (my structs have more internal variables, but they are not being returned either).
typedef struct {
double points;
FILE *file;
} Polygon;
void readobject(FILE *g, Polygon poly) {
fscanf(g, "%lf", &poly.points); //lets say this is reads in 6.0
printf("%lf\n", poly.points); //this will print 6.0
}
int main (int argc, char **argv){
Polygon polygon[argc];
int cc = 0;
polygon[cc].file = fopen(argv[cc], "r");
readobject(polygon[cc].file, polygon[cc]);
printf("%lf\n", polygon[cc].points); //This prints out 0.0
}
Why does this do that? How can I get it to return 6.0?