LoV_a
LoV_a

Reputation: 29

error: expected ‘{’ before ‘*’ token struct (C programming help)

I am getting the following error when I try to compile and run my code. " error: expected ‘{’ before ‘*’ token struct ".

    The code it is referring to:

    #ifndef node
    #define node
    struct node
    {
     int datum;
     struct node * next;
    }  ;
   #endif

The above code is for a user-defined header file called "node.h". It will be used to create a linked list.

Upvotes: 0

Views: 400

Answers (1)

kaylum
kaylum

Reputation: 14046

#define node

That will replace with an empty token wherever there is a node after that point. So after preprocessing the code becomes:

struct
{
 int datum;
 struct * next;
}  ;

So need to pick a name for the define that is not used as an identifier in the file. Commonly the define reflects the file name:

#ifndef NODE_H
#define NODE_H

struct node
{
    int datum;
    struct node * next;
};

#endif 

Upvotes: 1

Related Questions