Please,help I have a small problem HERE.

This is a discussion on Please,help I have a small problem HERE. within the C Programming forums, part of the General Programming Boards category; I am writting a C prog on Turbo C++ but I have an ERROR I cant Fix. The prog Code: ...

  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
    21,403
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 03: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

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