I created a linked list program it works perfect with ints in c. but if change the parameter to char array, and try to do a strcpy it causes a core dump.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
char mac[25];
struct node * next;
};
typedef struct node *list;
int main(void) {
lista c;
c = creoLista();
c = insert_start(c, "aa:bb:cc:dd:e1");
c = insert_start(c, "aa:bb:cc:dd:e2");
c = insert_start(c, "aa:bb:cc:dd:e3");
showList(c);
return 0;
}
list createList() {
return NULL;
}
list insert_start(list l1, char val[]) {
list n;
n =(list )malloc(sizeof(list));
strcpy(n->mac,val);
printf("ADDED: %s en ADDRESS:%p NEXT ADDRESS: %p\n", n->mac,(void *)(&n), (void *) (&n->next));
n -> next = l1;
return n;
}
void showList(list l1) {
while (l1 != NULL){
printf("Value: %s Address: %p\n",l1 -> mac,(void *) (&l1 -> next) );
l1 = l1 -> next;
}
}
Any hint on what im doing wrong and why it works with ints and not a char array
thanks