I'm trying to make a linked list, what's wrong with my syntax for adding a node?

struct data {
     char name[20];   
     char number[10]; 
};

typedef struct node {
     struct data list;
     struct node* next;
} Node;

Node *head = 0;
Node *tail = 0;
Node *New = 0;

void add(char* name, char* number) {
    New = (Node *) malloc(sizeof(Node));
    New->list.name = name;   /* incompatible type assignment, from char* to char[20] */
    New->list.number) = number;   /* same error */
    New->next = 0;

    if (tail != 0) {
        tail->next = New;
        tail = New;
    }
    else {
        tail = New;
        head = New;
    }
}

You can't assign an array of characters like that, here is how you correct it.

#include <stdio.h>

struct data {
     char name[20];   
     char number[10]; 
};

typedef struct node {
     struct data list;
     struct node* next;
} Node;

Node *head = 0;
Node *tail = 0;
Node *New = 0;

void add(char* name, char* number) {
    New = (Node *) malloc(sizeof(Node));
    sprintf_s( New->list.name, 20, name );
    sprintf_s( New->list.number, 10, number );
    New->next = 0;

    if (tail != 0) {
        tail->next = New;
        tail = New;
    }
    else {
        tail = New;
        head = New;
    }
}

Hope this helps :)

edit: heh, just realized its already been marked as solved ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.