Thread: assignmnet error

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    5

    assignmnet error

    I'm getting an error about the assignment of a value to my data type below, any suggestions would be helpful.

    Code:
    typedef struct node{ char data[100]; struct node *next; } Node;
    typedef struct list{ Node *head; Node *tail; int size;} LL;
    
    // initializer for memory
    blah;blah;blah;
    
    // error method
    void addLL( LL *ll, void *p )
    {
            Node *newNode;
    
            if( ( newNode = ( Node * )malloc( sizeof( Node ) ) ) == NULL )
                    return;
            // error is right here, doesnt like putting the void pointer
           // p into the char[100] of data
           // says incompatible types in assignment
            newNode->data = p;
            newNode->next = NULL;
    
            ll->tail->next = newNode;
            ll->tail = newNode;
            ll->size = (ll->size)+1;
    
            return;
    }
    Everything else is correct, I've verified with others. However, I cant figure out why the void pointer conversion doesnt work. Ive tried casting as a char* and it doesnt work either and a few friends couldnt help me either. Any help is appreciated.
    Last edited by KirbyMorph; 03-10-2003 at 05:10 PM.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    typedef struct node{ char data[100]; struct node *next; } Node;
    Here, data is an array. An array is not a pointer.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    170
    You can't assign a char[100] to a pointer, You need to either copy the data from 'P' to 'Data' or make 'Data' a char* then assign to 'P'.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM