Dove sbaglio????
codice:#include <stdio.h> #include <string.h> #include <stdio.h> #include <assert.h> #include <malloc.h> typedef int type; struct _list { type data; struct _list * next; }; typedef struct _list * lista; void inizializza(lista ptrls, type n); void aggiungi(lista ptrls, type n); void cancell(lista ptrls); void inizializza(lista ptrls, type n) { assert(ptrls != NULL); ptrls->data = n; ptrls->next = NULL; } void aggiungi(lista ptrls, type n) { assert(ptrls != NULL); lista aux = malloc(sizeof(struct _list)); // new list aux->data = n; aux->next = NULL; // -------- ptrls->next = aux; } void cancell(lista ptrls) { lista aux; while (ptrls != NULL) { aux = ptrls; ptrls = ptrls->next; free(aux); } } //main.cpp #include "list.h" int main( ) { lista l; inizializza(l, 9); aggiungi(l, 7); aggiungi(l, 5); aggiungi(l, 8); while(l->next != NULL) { printf("%d \n", l->data); l = l->next; } // cancell(l); system( "PAUSE" ); return 0; }

Rispondi quotando