我写了一个用结构体指针写的判断三角形的程序。编译没有报错,但是程序无法正常进行。调试完后发现数据就没有输入成功,调试报错为segmentation fault,请大家帮我看看是那里出错了。谢谢大家
#include<stdio.h>
#include<math.h>
typedef struct _point
{
double x;
double y;
} Point, *pPoint;
//求边长函数
double lengthCalculate(pPoint p1,pPoint p2);
//判断是否可以构成三角形函数
_Bool judge(pPoint p1, pPoint p2, pPoint p3);
int main(int argc, char const *argv[])
{
pPoint p1=NULL, p2=NULL, p3=NULL;
double L, A;
scanf("%lf %lf %lf %lf %lf %lf", &(p1->x), &(p1->y), &(p2->x), &(p2->y), &(p3->x), &(p3->y));
if(judge(p1,p2,p3))
{
L = lengthCalculate(p1, p2) + lengthCalculate(p2, p3) + lengthCalculate(p1, p3);
A = L * (L - lengthCalculate(p1, p2)) * (L - lengthCalculate(p2, p3)) * (L - lengthCalculate(p1, p3));
printf("L = %.2f, A = %.2f", L, A);
}
else
{
printf("Impossible");
}
return 0;
}
double lengthCalculate(pPoint p1,pPoint p2)
{
double length;
length = sqrt(pow(p1->x - p2->x, 2) + pow(p1->y - p2->y, 2));
return length;
}
_Bool judge(pPoint p1, pPoint p2, pPoint p3)
{
double length1, length2, length3;
length1 = lengthCalculate(p1, p2);
length3 = lengthCalculate(p1, p3);
length2 = lengthCalculate(p2, p3);
if(length1+length2>length3&&length3+length2>length1&&length1+length3>length2)
{
return 1;
}
else
{
return 0;
}
}