#include <stdio.h>
#include <math.h>
typedef struct {int x; int y;} Point;
int PointDist(Point);
int main()
{
Point d[2];
printf("Enter the x value of point1:");
scanf("%d",&d[0].x);
printf("Enter the y value of point1:");
scanf("%d",&d[0].y);
printf("Enter the x value of point2:");
scanf("%d",&d[1].x);
printf("Enter the y value of point2:");
scanf("%d",&d[1].y);
printf("The Euclidean distance between two Points is %lf",PointDist(d[2]));
system("pause");
return 0;
}
int PointDist(Point dot[2])
{
int a,b;
a=(dot[0].x-dot[1].x)+(dot[0].y-dot[1].y);
b=a+1;
return b;
}
运行时发生错误,咋回事啊
1、结构体数组传给指针,实质上是不可能的,本质上传的是数组首地址,根据偏移来操作数组,这样看起来好像是真在操作数组一样。就和普通指针一样使用,只不过它是结构体数组。
2、例程:
没有报错,而是运行后出现什么冲突(我是小白),不过照您说的改后就报错了,所以还需要怎样改呢,谢谢你热情的回答
追答int PointDist(Point);这句改成int PointDist(Point dot[])
int PointDist(Point dot[2])这句改成int PointDist(Point dot[])
整个改成这样:
#include
#include
typedef struct {int x; int y;} Point;
int PointDist(Point dot[]);
int main()
{
Point d[2];
printf("Enter the x value of point1:");
scanf("%d",&d[0].x);
printf("Enter the y value of point1:");
scanf("%d",&d[0].y);
printf("Enter the x value of point2:");
scanf("%d",&d[1].x);
printf("Enter the y value of point2:");
scanf("%d",&d[1].y);
printf("The Euclidean distance between two Points is %lf",PointDist(d));
system("pause");
return 0;
}
int PointDist(Point dot[])
{
int a,b;
a=(dot[0].x-dot[1].x)+(dot[0].y-dot[1].y);
b=a+1;
return b;
}