Thread: expected expression before ')' token

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    21

    Post expected expression before ')' token

    hi i am new to c, i keep getting this error. ":32: error: expected expression before ')' token"

    here is my code.
    Code:
    typedef struct{
        char* name;
        int comValue;
    }comName;
    
    
    typedef struct{
        comName* comName;
        struct node *next;
    }node;
    
    
    void insertNode(void){
        node *newNode = (node*)malloc(sizeof(node));
        
        //initialize node
        newNode->next = NULL;
        
    32    newNode->comName= (newNode*)malloc(sizeof(comName));
            
    }
    THANK YOU

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    newNode is the name of a variable, not the name of a type. A type conversion as in "(newNode *)" requires the name of a type.

    Unrelated to your problem .... it is a really bad idea, unless you enjoy the prospect of confusing yourself in future, to have variable names the same as type names.

    Also, conversions of the return value from malloc() are not necessary. But you must #include <stdlib.h>
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    21
    thank you grumpy.
    yes i did include stdlib.h,, i just forgot to paste it in the forum...

    now that i fixed that problem, i keep getting the error, ":32: error: 'comName' undeclared (first use in this function)"..!

    thanks

  4. #4
    Registered User
    Join Date
    Sep 2012
    Posts
    357
    Code:
        newNode->comName= (newNode*)malloc(sizeof(comName));
                                                  ^^^^^^^   <=== THIS comName

  5. #5
    Registered User
    Join Date
    Sep 2012
    Posts
    21
    haha,, thanks guys... i got confused for a second..! DD

  6. #6
    Time-Lord Victorious! The Doctor's Avatar
    Join Date
    Aug 2012
    Location
    Perth, Western Australia
    Posts
    50
    Quote Originally Posted by qny View Post
    Code:
        newNode->comName= (newNode*)malloc(sizeof(comName));
                                                  ^^^^^^^   <=== THIS comName
    And that's precisely why you don't have things with the same name ;-D

    I'm new too by the way! I'm enjoying programming in C, but have had a lot of problems.
    Code:
    if (codeWorks( code) && !youCanDoSomethingBetter( code) )
    {
         beHappy();
    } else
    {
         fixCode( code);
    }

  7. #7
    Registered User
    Join Date
    Jul 2012
    Location
    Australia
    Posts
    242
    Hey, The Doctor, I am also in Perth. Small world.

    And "expected expression before ')' token" is common for me too, as well as ) or ;
    Last edited by cfanatic; 09-14-2012 at 08:05 AM.
    IDE: Code::Blocks | Compiler Suite for Windows: TDM-GCC (MingW, gdb)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 08-09-2012, 12:48 PM
  2. expected primary-expression before xxx token
    By lehe in forum C++ Programming
    Replies: 5
    Last Post: 07-06-2009, 02:54 PM
  3. error: expected expression before ‘{’ token
    By nendariani in forum C Programming
    Replies: 7
    Last Post: 09-14-2008, 11:27 AM
  4. Replies: 7
    Last Post: 09-14-2008, 08:37 AM
  5. Expected primary expression before '<<' token...
    By RpgActioN in forum C++ Programming
    Replies: 3
    Last Post: 08-05-2005, 10:40 PM