Thread: Header file error

  1. #1
    Registered User
    Join Date
    Oct 2018
    Posts
    21

    Header file error

    I'm using a makefile, but anyways this is my struct.h file

    Code:
    #ifndef struct
    #define struct
    
    typedef struct person{
        char *name;
        int socialNum;
        char *dateOfBirth;
    }person_t;
    
    typedef struct flights{
        char *flnum;
        char *from;
        char *to;
        char *date;
        float price;
        person_t *fPerson;
    }flights_t;
    
    #endif
    And this is my error from the terminal:

    Code:
    gcc -Wall -c bookAFlight.c
    In file included from bookAFlight.h:7:0,
                     from bookAFlight.c:1:
    struct.h:4:22: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
     typedef struct person{
                          ^
    struct.h:8:2: warning: data definition has no type or storage class
     }person_t;
      ^~~~~~~~
    struct.h:8:2: warning: type defaults to ‘int’ in declaration of ‘person_t’ [-Wimplicit-int]
    struct.h:10:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
     typedef struct flights{
                           ^
    struct.h:17:2: warning: data definition has no type or storage class
     }flights_t;
      ^~~~~~~~~
    struct.h:17:2: warning: type defaults to ‘int’ in declaration of ‘flights_t’ [-Wimplicit-int]
    Now I dont see whats wrong with my struct.h file tbh, if anyone can point it out.
    Thanks.
    Last edited by JohnnyC; 06-02-2019 at 06:59 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Eh. Never use a reserved word as a header guard name. Change this:
    Code:
    #ifndef struct
    #define struct
    To something like this:
    Code:
    #ifndef STRUCT_H
    #define STRUCT_H
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Have you tried removing those #ifndef struct and #define struct lines?

  4. #4
    Registered User
    Join Date
    Oct 2018
    Posts
    21
    Oh yea lol I forgot about that (reserved word as a header guard name), thanks I got rid of the struct.h file errors. But I got a dozen new ones

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Odd error on header file inclusion
    By anatoly in forum C Programming
    Replies: 5
    Last Post: 05-30-2010, 12:20 PM
  2. New to C++, Header File Error
    By kspill2 in forum C++ Programming
    Replies: 2
    Last Post: 09-09-2007, 02:34 PM
  3. C2061 error in header file
    By nappaji in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2007, 05:46 PM
  4. header file error
    By beon in forum C Programming
    Replies: 7
    Last Post: 11-16-2006, 07:33 AM
  5. header file compile error
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 02-23-2002, 06:28 AM

Tags for this Thread