errors in c program

This is a discussion on errors in c program within the C Programming forums, part of the General Programming Boards category; hello, can someone kindly correct the errors in my c program.i am unable to get the errors. my program is: ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    3

    errors in c program

    hello,

    can someone kindly correct the errors in my c program.i am unable to get the errors.
    my program is:

    doc.c(starts from line 22):
    Code:
    struct element *new_doc( int i, const char *name)
    {
          struct element *e = malloc( sizeof( struct element) );
          if( e == NULL)
          {
              yyerror( "new_node: malloc failed");
              exit(1);
          }
          e->name = name;
          e->type = i;
          e->next = NULL;
          return e;
    }
       
    void append_doc(struct element *e)
    {
      e->name = name;
      e->type = i;
      e->next = head;
      head = e;
    }
    doc.h:
    Code:
    typedef struct element
    {
      char *name;
      int type;
      struct element *next;
    }Documen;
    
    struct element *head = NULL;
    
      
    void append_doc( struct element *e);
    
    struct element *new_doc( int i,const char *name);
    errors:

    doc.c: In function `new_doc':
    doc.c:30: warning: assignment discards qualifiers from pointer target type
    doc.c: In function `append_doc':
    doc.c:38: `name' undeclared (first use in this function)
    doc.c:38: (Each undeclared identifier is reported only once
    doc.c:38: for each function it appears in.)
    doc.c:39: `i' undeclared (first use in this function)


    Regards,
    Akshara

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    >> e->name = name;
    you can't do that... you'll want some kind of strcpy(), or something.

    In your function 'append_doc' there is no variable called name or i. I believe you're mixing them up with the new_doc function. You're going to have to add more parameters to the function.

    Code:
    void append_doc(struct element *e)
    {
      e->name = name;
      e->type = i;
      e->next = head;
      head = e;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 02:42 AM
  2. mega compile errors for small program
    By s_UNI_ in forum C++ Programming
    Replies: 4
    Last Post: 04-28-2005, 01:00 PM
  3. Errors with program
    By nizbit in forum C Programming
    Replies: 37
    Last Post: 12-19-2004, 09:56 PM
  4. Average Rainfall Program Errors
    By JamesAnthony23 in forum C Programming
    Replies: 1
    Last Post: 09-11-2002, 11:44 PM
  5. I'm a newbie and I can't understand the errors in my program
    By iluvmyafboys in forum C++ Programming
    Replies: 19
    Last Post: 02-20-2002, 10:40 AM

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