Like Tree3Likes
  • 1 Post By grumpy
  • 2 Post By qny

expected expression before ')' token

This is a discussion on expected expression before ')' token within the C Programming forums, part of the General Programming Boards category; hi i am new to c, i keep getting this error. ":32: error: expected expression before ')' token" here is ...

  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,674
    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>
    m_programmer likes this.
    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, Sunshine, 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
    qny
    qny is offline
    Registered User
    Join Date
    Sep 2012
    Posts
    355
    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 09: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, 01:48 PM
  2. expected primary-expression before xxx token
    By lehe in forum C++ Programming
    Replies: 5
    Last Post: 07-06-2009, 03:54 PM
  3. error: expected expression before { token
    By nendariani in forum C Programming
    Replies: 7
    Last Post: 09-14-2008, 12:27 PM
  4. Replies: 7
    Last Post: 09-14-2008, 09:37 AM
  5. Expected primary expression before '<<' token...
    By RpgActioN in forum C++ Programming
    Replies: 3
    Last Post: 08-05-2005, 11:40 PM

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