C Parse errors

This is a discussion on C Parse errors within the C Programming forums, part of the General Programming Boards category; Hi.. I am having a problem with a struct datatype. Even after including the header file, my program keeps giving ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    1

    C Parse errors

    Hi..

    I am having a problem with a struct datatype. Even after including the header file, my program keeps giving me the following parse messages for each of the functions. The following are the errors for the function create.

    prototype in the lp.h file is

    struct {
    int x;
    int y;
    }lp;

    lp create(int, int);

    Errors:::::
    lp.h:9: parse error before `create'
    lp.h:9: warning: data definition has no type or storage class
    lp.h:10: warning: parameter names (without types) in function declaration
    lp.h:11: warning: parameter names (without types) in function declaration

    Am I making a mistake in the declaration of lp??

    Any hints/leads would be appreciated.

    Thanks.
    Aimal

  2. #2
    Unregistered
    Guest
    struct {
    int x;
    int y;
    }lp;

    lp create(int, int);

    the fucntion only returns one variable;
    try using pointers

    void create(int a,int b)
    { lp *new;
    new->x=a;
    new->y=b;
    }

  3. #3
    Unregistered
    Guest

    C Parse errors

    thanks for the hint but my functions have to return an lp type struct object..

    Do I have to return a struct datatype as a pointer ??

    Thanks

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    In your code lp is a variable. You want lp to be a type, so you should do:

    typedef struct {
    int x;
    int y;
    }lp;

  5. #5
    Registered User PutoAmo's Avatar
    Join Date
    Mar 2002
    Posts
    72
    or ...

    Code:
    struct lp {
    int x;
    int y;
    }

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > Do I have to return a struct datatype as a pointer ??


    No. You do not have to.
    Code:
    struct mystruct { int x; int y; char z; };
    
    struct mystruct myfunction( void )
    {
        struct mystruct m;
        m.x = 10;
        m.y = 20;
        m.z = 'c';
        return m;
    }
    
    struct mystruct x;
    
    x = myfunction( );
    This will work fine, by assigning the value to 'x'.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. string ?
    By cogeek in forum C Programming
    Replies: 27
    Last Post: 12-05-2004, 09:45 PM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21