// triangle.h
struct posn {
int x;
int y;
};
// struct is_right_triangle(p1, p2, p3)
struct is_right_triangle(const struct posn *p1, const struct posn *p2,
const struct posn *p3);
struct is_right_triangle(const struct posn *p1, const struct posn *p2,
const struct posn *p3) {
const int a = (p1->x - p2->x)*(p1->x - p2->x) + (p1->y - p2->y)*(p1->y - p2->y);
const int b = (p1->x - p3->x)*(p1->x - p3->x) + (p1->y - p3->y)*(p1->y - p3->y);
const int c = (p3->x - p2->x)*(p3->x - p2->x) + (p3->y - p2->y)*(p3->y - p2->y);
if (a + b == c) {
return *p1;
} else if (b + c == a) {
return *p2;
} else if (a + c == b) {
return *p3;
} else {
return NULL;
}
}
为什么我会收到此错误:
./triangle.h:13:26: error: expected identifier or '(' struct is_right_triangle(const
struct posn *p1, const struct posn *p2, const struct posn *p3); ^
./triangle.h:13:26: error: expected ')'
./triangle.h:13:25: note: to match this '(' struct is_right_triangle(const struct posn *p1, const struct posn *p2, const struct posn *p3);