D
DanielJohnson
I wrote a simply program with a 3 D coordinate called point. I am
adding two points, taking their distance etc. gcc compiler is not
identifying the struct. Here is the code. I get bunch of errors. The
main ones are : useless storage class specifier in empty declaration,
'point' undeclared (first use in this function), 'p1' undeclared
(first use in this function) etc. Any help will be appreciated. Thanks
#include <stdio.h>
#include <math.h>
/* create a 3d point struct*/
typedef struct point{
int x,y,z;
};
/* Function declaration*/
float dist(point *, point *);
point add(point *, point *);
void display(point *);
int main(void)
{
point p1,p2,p3;
p1.x=2;p1.y=4;p1.z=5;
p2.x=5;p1.y=2;p1.z=6;
printf("\n dist = %f", dist(&p1,&p2));
add(&p1, &p2);
display(&p3);
return;
}
float dist(point *a, point *b)
{
float length=0.0;
length = sqrt( (a->x-b->x)*(a->x-b->x)+ (a->y-b->y)*(a->y-b->y)+
(a->z-b->z)*(a->z-b->z));
return length;
}
point add(point *a, point *b)
{
point temp;
temp.x=a->x + b->x;
temp.y=a->y + b->y;
temp.z=a->z + b->z;
return temp;
}
void display(point *a)
{
printf("\npoint= %d,%d,%d\n",a->x,a->y,a->z);
}
adding two points, taking their distance etc. gcc compiler is not
identifying the struct. Here is the code. I get bunch of errors. The
main ones are : useless storage class specifier in empty declaration,
'point' undeclared (first use in this function), 'p1' undeclared
(first use in this function) etc. Any help will be appreciated. Thanks
#include <stdio.h>
#include <math.h>
/* create a 3d point struct*/
typedef struct point{
int x,y,z;
};
/* Function declaration*/
float dist(point *, point *);
point add(point *, point *);
void display(point *);
int main(void)
{
point p1,p2,p3;
p1.x=2;p1.y=4;p1.z=5;
p2.x=5;p1.y=2;p1.z=6;
printf("\n dist = %f", dist(&p1,&p2));
add(&p1, &p2);
display(&p3);
return;
}
float dist(point *a, point *b)
{
float length=0.0;
length = sqrt( (a->x-b->x)*(a->x-b->x)+ (a->y-b->y)*(a->y-b->y)+
(a->z-b->z)*(a->z-b->z));
return length;
}
point add(point *a, point *b)
{
point temp;
temp.x=a->x + b->x;
temp.y=a->y + b->y;
temp.z=a->z + b->z;
return temp;
}
void display(point *a)
{
printf("\npoint= %d,%d,%d\n",a->x,a->y,a->z);
}