what does this error mean?

This is a discussion on what does this error mean? within the C Programming forums, part of the General Programming Boards category; Here is the error message I get: c:\program files\miracle c\linklistex.c: line 9: Parse Error, expecting `SEP' 'node *head=0, *tail=0' aborting ...

  1. #1
    Unregistered
    Guest

    what does this error mean?

    Here is the error message I get:

    c:\program files\miracle c\linklistex.c: line 9: Parse Error, expecting `SEP'
    'node *head=0, *tail=0'
    aborting compile

    Here is my code:

    #include <stdio.h>

    struct node
    {
    char value;
    struct node *next;
    };

    node *head=NULL, *tail=NULL;

    void addNode(char);
    void printList();

    void main()
    {
    char input;

    printf("Enter you name:\n");
    input = getchar();
    while( input != '\n' )
    {
    addNode( input );
    input = getchar();
    }

    printf("\nYou have entered: ");
    printList();

    printf("\n\nProgram complete\n");
    }

    void addNode( char val )
    {
    node *insert;

    insert = new node;
    insert->value = val;
    insert->next = NULL;

    if( head == NULL ) //if the list is empty
    head = tail = insert;
    else
    {
    tail->next = insert;
    tail = insert;
    }
    }

    void printList()
    {
    node *p = head;

    while( p != NULL )
    {
    printf("%c", p->value );
    p = p->next;
    }
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    struct node
    {
    char value;
    struct node *next;
    };

    node *head=NULL, *tail=NULL;
    In C, this is not valid code. You cannot simply use 'node'. You must do:

    struct node *head = NULL; *tail = NULL;

    You have to have the 'struct' keyword unless you're using a #define or a typedef.

    typedef struct node Node;

    Node *head = NULL, *tail = NULL;

    Or

    #define struct node NODE;

    NODE *head = NULL, *tail = NULL;

    void main()
    This is wrong.

    int main( )

    Or:

    int main( void )

    'void main' is not correct. It is wrong. Read the FAQ.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Unregistered
    Guest
    I changed void main() to int main() and it still does it

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I changed void main() to int main() and it still does it
    And did you make the first change the quzah suggested?
    In C, this is not valid code
    void main is undefined, invalid and undefined are two different things. Undefined will probably compile, but invalid will not. Both are incorrect, but one will at least stop you from doing it

    -Prelude
    My best code is written with the delete key.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    void main is undefined, invalid and undefined are two different things. Undefined will probably compile, but invalid will not. Both are incorrect, but one will at least stop you from doing it
    You are misquoting me. I stated that:

    struct node { int x; };

    node y;

    Is invalid code. This is not valid C code, while it is valid C++ code.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    And did you make the first change the quzah suggested?
    he wasn't misquoting you, he was refering to 2 sperate things that are both incorrect, one being invalid and the other being undefined.

    and prelude.. do you search for void main() every time you log in or something!

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Gotcha. Actually, I brought up 'void main' first. While I don't search for it, I do point it out when I see it.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

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