Issue
I'm a new C programmer,
the program I was writing has to return 0 if the points are colinear, otherwise it has to return 1. I've split the code in .h and .c. This is the code: [geometry.c]
struct point {
int x;
int y;
} p1;
struct point {
int x;
int y;
} p2;
struct point {
int x;
int y;
} p3;
int colinear(struct point* p1, struct point* p2, struct point* p3) {
if (((p1->x - p2->x)* (p1->y - p2->y) == ((p3->y - p2->y) * (p1->x - p2->x))))
return 0;
else
return 1;
}
and: [geometry.h]
#ifndef geometry.h
#define geometry.h
#endif
#include "geometry.c"
extern int colinear(struct point *p1, struct point *p2, struct point *p3);
Using the debugger: "C2011: 'point': 'struct' type redefinition".
Where are the errors?
Solution
No Need to define 3 times
struct point {
int x;
int y;
} p1;
struct point {
int x;
int y;
} p2;
struct point {
int x;
int y;
} p3;
define only once, and create variables as you wish.
struct point {
int x;
int y;
};
struct point p1,p2,p3;
Answered By - IrAM Answer Checked By - Robin (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.