Trying to convert some structs from being accessed by value to accessed by pointer, and I'm being told:
[Error] request for member 'point' in something not a structure or a union
Do I need to reference the variable 'point[]' as a pointer as well?
/*
* File: Distance between multiple points
* Project: Personal
* Author: Christopher Bowers
* Version: Version 1.0 | Basic frame made
* 2.0 | Changing to pointers to pass # of points
*/
#include <stdio.h>
#include <stdlib.h> // for EXIT_SUCESS and rand()
#include <math.h> // for sqrt()
typedefstruct {
double x;
double y;
} Point;
#define NUM_POINTS 4
typedefstruct {
Point point[NUM_POINTS];
} Coord;
// How to exit on '\n' ?
// Use of if statements on failed condition?
int getPoints(Coord p1) {
int i = 0;
printf("Enter x value (1) >> ");
for (i = 0; i < NUM_POINTS && scanf("%lf", (&p1).point[i].x); i++) {
printf("Enter y value (%d) >> ", i + 1);
scanf("%lf", (&p1).point[i].y);
if(i < 3)
printf("Enter x value (%d) >> ", i + 2);
}
return i;
}
double distCalc(Coord p1, constint numPoints) {
int i = 0;
double dist = 0;
double diff1 = 0;
double diff2 = 0;
for (i = 0; i < numPoints; i += 2) {
diff1 = (&p1).point[i].x - (&p1).point[i+1].x;
diff2 = (&p1).point[i].y - (&p1).point[i+1].y;
dist += sqrt(diff1 + diff2);
}
return dist;
}
int main(void) {
int i = 0;
int pointsInput = 0;
double distSum = 0;
Coord p;
puts("Distance calculator V.1");
pointsInput = getPoints(p);
distSum = distCalc(p, pointsInput);
printf("Total distance is: %.4f", distSum);
return EXIT_SUCCESS;
}