xchè mi dà un segmentation fault?
a me sembra corretta
forse l'ultimo paus->next = NULL; è impostato male?
codice:#include <stdio.h> #include <stdlib.h> struct hello { int inf; struct hello *next; }; void creaPrimo(int ins); void creaAltri(int ins); main() { int ins; struct hello *p, *paus; printf("Inserisci il primo elemento:\n"); scanf("%d", &ins); /* Caso primo elemento */ if(ins == 0) p = NULL; else { creaPrimo(ins); paus = p->next; /* Caso altri elementi */ do { printf("Inserisci elementi successivi:\n"); scanf("%d", &ins); creaAltri(ins); } while (ins != 0); paus->next = NULL; } } void creaPrimo(ins) { int size; struct hello *p; size = sizeof(struct hello); p = (struct hello*)malloc(size); p->inf = ins; p->next = NULL; } void creaAltri(ins) { int size; struct hello *paus; size = sizeof(struct hello); paus = (struct hello*)malloc(size); paus->inf = ins; paus = paus->next; }


Rispondi quotando