I can't figure out this compiler error

This is a discussion on I can't figure out this compiler error within the C Programming forums, part of the General Programming Boards category; I have defined a linked list as follows: Code: struct node{ char word[9]; struct node *next; }; typedef struct node ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    32

    I can't figure out this compiler error

    I have defined a linked list as follows:
    Code:
    struct node{
      char word[9];
      struct node *next;
    };
    typedef struct node NODE;
    and I tried using this code to add a new word to the linked list:
    Code:
    void push(NODE **headref, char string[9])
    {
        NODE *newnode=malloc(sizeof(NODE));
    
        newnode->word=string; /*LINE 65*/
        newnode->next=*headref;
        *headref=newnode;
    }
    but I get a complier error saying that in line 65 I do not have compatible types.
    Can anyone help me figure this out?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > newnode->word=string; /*LINE 65*/

    Try strcpy() in string.h:

    strcpy(newnode->word, string);

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    32
    thanks guys

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    175
    Array name is constant pointer. And you can not change the constants.

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >Array name is constant pointer.

    No, it is not.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    I wouldn't use strcpy, I would just make that point to the string.

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >I wouldn't use strcpy, I would just make that point to the string.

    Make what point to the string? The array newnode->word? Like this?
    Code:
    newnode->word=string; /*LINE 65*/
    To me it sounds like you're saying you'd prefer to come from the solution back to the original problem.

    Arrays and Pointers
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by chrismiceli
    I wouldn't use strcpy, I would just make that point to the string.
    This is a common raction here. It goes something like this:

    "I have this problem, and while you have given me the answer, I don't like the answer you've given. I want to do it my way. Even though it's wrong and it doesn't work."

    To which we usually reply:

    "Fine, do it your way. However, don't keep asking why it doesn't work when you refuse to use the answer given to you."

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  3. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 01:17 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM

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