che casino...
posso lasciarlo in 2 funzione separate la creazione degli elementi? o devo usarne per forza uno?
codice:
#include <stdio.h>
#include <stdlib.h>
struct hello {
int inf;
struct hello *next;
};
struct hello *creaPrimo(int ins);
struct hello *creaAltri(int ins);
main()
{
int ins;
struct hello *p, *paus;
struct hello *listaPtr;
printf("Inserisci il primo elemento:\n");
scanf("%d", &ins);
/* Caso primo elemento */
if(ins == 0)
p = NULL;
else {
listaPtr = creaPrimo(ins);
paus = p->next;
/* Caso altri elementi */
do {
printf("Inserisci elementi successivi:\n");
scanf("%d", &ins);
listaPtr = creaAltri(ins);
} while (ins != 0);
paus->next = NULL;
}
}
struct hello *creaPrimo(ins) {
int size;
struct hello *p;
size = sizeof(struct hello);
p = (struct hello*)malloc(size);
p->inf = ins;
p->next = NULL;
return p;
}
struct hello *creaAltri(ins) {
int size;
struct hello *p,*paus;
size = sizeof(struct hello);
paus = (struct hello*)malloc(size);
paus->inf = ins;
paus = paus->next;
return p;
}