PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 27, 2022

[FIXED] how to solve type redefinition error in this C program

 April 27, 2022     c, compiler-errors, warnings     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing