# Thread: Accessing structs in functions

1. ## Accessing structs in functions

Im having some issues while referring to values passed to a function from a pointer.

Code:
```typedef struct {
double x;
double y;
} Point;

typedef struct {
Point angle0;
Point angle1;
Point angle2;
} Triangle;

int main() {
Triangle T;
T.angle0 = enterPoint();
T.angle1 = enterPoint();
T.angle2 = enterPoint();
printVertices(&T);
printf ("The perimeter is %.2f", getPerimeter(&T));
}

void printVertices(const Triangle *tr) {
printf ("The point coordinates are: ");
printf ("[%.2f, %.2f], ", tr->angle0.x, tr->angle0.y);
printf ("[%.2f, %.2f], ", tr->angle1.x, tr->angle1.y);
printf ("and [%.2f, %.2f]\n", tr->angle2.x, tr->angle2.y);
}

double distanceBetweenPoints(const Point *p1, const Point *p2) {
double x = (p2->x - p1->x) * (p2->x - p1->x);
double y = (p2->x - p1->y) * (p2->x - p1->y);
double distance = sqrt(x+y);
return distance;
}

double getPerimeter(const Triangle* tr) {
double a, b, c;
a = distanceBetweenPoints((*tr).angle0, (*tr).angle1);
b = distanceBetweenPoints(&tr.angle1, &tr.angle2);
c = distanceBetweenPoints(&tr.angle2, &tr.angle0);
double perimeter = a + b + c;
return perimeter;
}```
My issue lies in getPerimeter(). I have tried multiple solutions of grabbing the values stored in the 'tr' variable but I've had many errors. Incompatible types, request for member in something not a structure or union, and too few argument errors. Please assist me in calling the values of tr.angle0 , tr.angle1, and tr.angle2 in the getPerimeter() function

nvm. Solved with distanceBetweenPoints(&tr->angle0, &tr->angle1); 2. Good to hear that you've solved it yourself. Have you considered naming those members points rather than angles, since the type is Point after all? I suspect readers would expect an angle to be a quantity in radians or degrees, rather than a Point. Popular pages Recent additions double, p2-x, point, printf, [%.2f 