-1

Heres a snippet from the code I am trying to complete for building a linked list. for some reason I keep getting the error "error: expected ‘;’, identifier or ‘(’ before ‘struct’ " when trying to compile the code. Can someone help me out.

struct node;
struct node* buildList(int x);
void push(struct node** headRef, int data);
int findLen(struct node** headRef);

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

struct node* buildList(int x){
   struct node* head = NULL;
   head = malloc(sizeof(struct node));

   head->data = x;
   head->next = NULL;

   return head;
}
7
  • just missing a semicolon at the end of you struct, struct node { ..... }; Mar 4, 2015 at 20:41
  • okay so in C you must put semicolon at end of every struct? Mar 4, 2015 at 20:57
  • yes pretty much. there are some contrived counter examples. Mar 4, 2015 at 21:13
  • If this question is about C, please remove the C++ tag. Also the other way around.
    – dfeuer
    Mar 5, 2015 at 0:36
  • @dfeuer, the same problem can arise in C or C++. I don't fully understand your complaint. Mar 5, 2015 at 8:56

1 Answer 1

3

Try putting a semicolon after the struct declaration

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.