Thread: please help I cannot find the error in this library containing a struct and functions

  1. #1
    Registered User
    Join Date
    Dec 2012
    Location
    Aigáleo, Greece, Greece
    Posts
    2

    please help I cannot find the error in this library containing a struct and functions

    Hello everyone, im new on the forums and I need a little bit of help for this programm (named ask4) that is calculating the distance of a point from (0,0), a point from another one and the area of a triangle. I have a problem with the libraries... (I think)

    Point.c:
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include "Point.h"
    
    struct POINT
    {
        double x;
        double y;
    };
    
    void Display(Point *A)
    {
        printf("%lf %lf\n",A->x,A->y);
    }
    
    double Distance(Point *p1)
    {
        return sqrt(pow(p1->x,2)+pow(p1->y,2));
    }
    
    double Distance2(Point *p1, Point *p2)
    {
        return sqrt(pow(p1->x - p2->x,2)+pow(p1->y - p2->y,2));
    }
    
    double Area(Point *p1, Point *p2, Point *p3)
    {
        double t;
        t=(Distance2(p1,p2)+Distance2(p2,p3)+Distance2(p1,p3))/2;
        return sqrt(t*(t-Distance2(p1,p2))*(t-Distance2(p2,p3))*(t-Distance2(p1,p3)));
    }
    Point.h:
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    
    typedef struct POINT Point;
    
    void Display(Point *);
    double Distance(Point *);
    double Distance2(Point *, Point *);
    double Area(Point *, Point *, Point *);
    ask4.c:
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include "Point.h"
    
    int main(void){
    
        Point p1;
        p1.x=15;
        p1.y=7;
        Point p2;
        p2.x=25;
        p2.y=14;
        Point p3;
        p3.x=19;
        p3.y=20;
        Display(&p1);
        printf("%lf\n",Distance(&p1));
        printf("%lf\n",Distance2(&p1,&p2));
        printf("%lf\n",Area(&p1, &p2, &p3));
    
    return 0;
    }
    the errors that I get are:

    C:\Users\Sifd\Desktop\ask4.c(8): error #2149: Undefined size for 'p1' with type 'Point'.
    C:\Users\Sifd\Desktop\ask4.c(9): error #2152: Unknown field 'x' of 'Point'.
    C:\Users\Sifd\Desktop\ask4.c(10): error #2152: Unknown field 'y' of 'Point'.
    C:\Users\Sifd\Desktop\ask4.c(11): error #2149: Undefined size for 'p2' with type 'Point'.
    C:\Users\Sifd\Desktop\ask4.c(12): error #2152: Unknown field 'x' of 'Point'.
    C:\Users\Sifd\Desktop\ask4.c(13): error #2152: Unknown field 'y' of 'Point'.
    C:\Users\Sifd\Desktop\ask4.c(14): error #2149: Undefined size for 'p3' with type 'Point'.
    C:\Users\Sifd\Desktop\ask4.c(15): error #2152: Unknown field 'x' of 'Point'.
    C:\Users\Sifd\Desktop\ask4.c(16): error #2152: Unknown field 'y' of 'Point'.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,616
    Have you heard of an opaque pointer? I think you have unintentionally coded a type that works that way. If you want to use Point normally, define the type in the header file, not any source file.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,627
    This
    Code:
    struct POINT
    {
        double x;
        double y;
    };
    needs to be in your .h file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Dec 2012
    Location
    Aigáleo, Greece, Greece
    Posts
    2
    Quote Originally Posted by Salem View Post
    This
    Code:
    struct POINT
    {
        double x;
        double y;
    };
    needs to be in your .h file.
    thank you, now its working

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How does an executable find a shared library?
    By django in forum C Programming
    Replies: 4
    Last Post: 08-26-2011, 10:05 AM
  2. cannot find library in makefile
    By steve1_rm in forum C Programming
    Replies: 8
    Last Post: 01-28-2009, 06:33 AM
  3. huh? ld can't find library that is in /usr/lib
    By zoubidoo in forum C++ Programming
    Replies: 5
    Last Post: 05-28-2008, 08:18 AM
  4. strange linking error -- can not find shared library
    By George2 in forum C Programming
    Replies: 2
    Last Post: 07-10-2006, 10:51 PM
  5. Can't find library although I specify where it should look
    By Shogun in forum Linux Programming
    Replies: 4
    Last Post: 11-23-2004, 07:54 AM