Luc@s, il tuo codice contiene un 'errore importante, overo il fatto che non allochi la memoria per il campo 'el' della struttura che deve contenere la stringa, ecco il codice corretto:
codice:
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <malloc.h>
struct List
{
char *el;
struct List *next;
struct List *prev;
};
void init(struct List *aux, char *el);
void add(struct List *aux, char *el);
void init(struct List *aux, char *el)
{
assert(aux != NULL);
//Bisogna allocare la memoria prima di effettuare la copiatura
aux -> el = (char *)malloc(100 * sizeof(char));
strcpy(aux->el, el);
aux->next = NULL;
aux->prev = NULL;
}
void add(struct List *aux, char *el)
{
assert(aux != NULL);
while(aux->next != NULL)
aux = aux->next;
struct List *tmp = (struct List *)malloc(sizeof(struct List));
//Bisogna allocare la memoria prima di effettuare la copiatura
tmp -> el = (char *)malloc(100 * sizeof(char));
strcpy(tmp->el, el);
tmp->next = NULL;
tmp->prev = aux;
aux->next = tmp;
}
int main(int argc, char *argv[])
{
struct List *head = (struct List *)malloc (sizeof(struct List));
init(head, "Luca1");
add(head, "Luca2");
add(head, "Luca3");
while(head != NULL)
{
printf("%s\n", head->el);
head = head->next;
}
char c[10];
scanf("%s", c);
return 0;
}