得到“错误:预期标识符或'('”

时间:2013-10-16 05:48:09

标签: c

// 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);

1 个答案:

答案 0 :(得分:4)

您没有指定要返回的结构类型。试试这个:

const struct posn *is_right_triangle(const struct posn *p1, const struct posn *p2, const struct posn *p3) {