Thread: Please,help I have a small problem HERE.

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    3

    Unhappy Please,help I have a small problem HERE.

    I am writting a C prog on Turbo C++ but I have an ERROR I cant Fix.

    The prog
    Code:
    typedef structnode
    {                                    ----> line 7
    int data;
    struct *next;
    struct *prev;
    };NODE
    
    void inserttop()                   --->line 13
    {
    int x;
    NODE *p;
    p=(NODE *)malloc(sizeof(NODE));
    The ERRORs
    Code:
    Compiling HW4.CPP:
    Error HW4.CPP 7: , expected
    Error HW4.CPP 13: Declaration syntax error
    if any one can help please reply...
    Last edited by joseph.w.s; 04-10-2009 at 06:14 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    It looks like two simple typo errors. The struct definition should be:
    Code:
    typedef struct node
    {
    int data;
    struct *next;
    struct *prev;
    } NODE;
    But I suggest reserving fully capitalised names for macro names.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Perhaps even:
    Code:
    typedef struct node
    {
    int data;
    struct node *next;
    struct node *prev;
    } NODE;
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    3
    Quote Originally Posted by laserlight View Post
    It looks like two simple typo errors. The struct definition should be:
    Code:
    typedef struct node
    {
    int data;
    struct *next;
    struct *prev;
    } NODE;
    But I suggest reserving fully capitalised names for macro names.

    ok i correct it to -->
    Code:
    typedef struct node
    {
    int data;
    struct node*next;
    struct node*prev;
    };NODE
    
    void inserttop()             ---> line 13
    {
    int x;
    NODE *p;
    p=(NODE *)malloc(sizeof(NODE));
    and it gives me now-->
    Code:
    Compiling HW4.CPP:
    Error HW4.CPP 13: Declaration syntax error

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You still have a surplus semicolon (or rater, one in the wrong place!)

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Apr 2009
    Posts
    3
    Quote Originally Posted by matsp View Post
    You still have a surplus semicolon (or rater, one in the wrong place!)

    --
    Mats
    I don'y know where ??

    Code:
    void inserttop()
    {
    int x;
    node *p;
    p=(NODE *)malloc(sizeof(NODE));
    printf("Please,Enter your Data");
    scanf("%d",&x);
    p->data=x;
    if(list!= NULL)
    {
    p->next=list;
    p->prev=NULL;
    list->prev=p;
    list=p;
    }
    else
    {
    p->next=NULL;
    P->prev=NULL;
    list=p;
    }
    }

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Two lines above what you just posted - there should be NO semicolon between typedef and the name you give the new type, but there should be one AFTER the defined types name.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Small Problem with double and integer adding?
    By Nathan the noob in forum C++ Programming
    Replies: 5
    Last Post: 03-28-2009, 04:16 PM
  2. Visual C++ small problem
    By gadu in forum C++ Programming
    Replies: 0
    Last Post: 03-10-2009, 10:45 PM
  3. Small problem with this array...
    By Merholtz in forum C Programming
    Replies: 7
    Last Post: 11-03-2008, 04:16 PM
  4. Help with a small problem (beginner)
    By piffo in forum C Programming
    Replies: 13
    Last Post: 09-29-2008, 04:37 PM
  5. Need Big Solution For Small Problem
    By GrNxxDaY in forum C++ Programming
    Replies: 8
    Last Post: 08-01-2002, 03:23 AM