Ahoy there mates!
I'm having a problem here... I asked a couple of my friends and they say there's nothing wrong with this code, so I can't figure out what's the problem...
I have declared four global pointers and i need to call them in a function(posted next). These are pointers to a double linked list.
Code:
typedef struct NODE {
struct NODE *next;
struct NODE *prev;
char name[BUFFDIM]
} node;
node *first_list1 = NULL;
node *last_list1 = NULL;
node *first_list2 = NULL;
node *last_list2 = NULL;
void insert(node *first, node *last, char *as) {
node *new = first;
node *n;
if(first==NULL) {
first = (node *) malloc(sizeof(node));
strcpy(first->name, as);
first->next = NULL;
first->prev = NULL;
last = first;
}
else {
while(n->next != NULL) {
n = n->next;
}
new = (node*) malloc(sizeof(node));
strcpy(new->name, as);
new->prev = n;
n->next = new;
last = new;
}
}
the thing is, if i call the function insert with one of those pointers (first_list1 or first_list2) and they're NULL, they don't change their value to point to a node...
the "last" ones don't too.