|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 | |
|
Senior Member
Iscritto dal: May 2004
Città: Pianeta Terra
Messaggi: 1593
|
[C] Problema lista! uffa
Ciao a tutti, mi sto esercitando nel fare delle liste, ma in tutte quelle che ho fatto, durante la compilazion mi esce sempre lo stesso errore....
Allora ho deciso di ristudiare il tutto e di provare a fare un programma di prova sulle liste, che ho trovato on-line... vi posto il codice Codice:
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
struct elemento
{
int inf;
struct elemento *pun;
}
struct elemento *crea_lista();
void visualizza_lista (struct elemento *);
int main ()
{
struct elemento *lista;
lista = crea_lista();
visualizza_lista (lista);
return 0;
}
struct elemento *crea_lista()
{
struct elemento *p, *punt;
int i, n;
printf ("n specificare il numero di elementi da inserire: ");
scanf ("%d", &n);
if (n==0)
{
p= NULL;
}
else
{
p= (struct elemento *)malloc(sizeof(struct elemento));
printf ("nInserisci il primo valore: ");
scanf("%d", p->inf);
punt = p;
for (i=2; i<=n; i++)
{
punt->pun= (struct elemento *)malloc(sizeof(struct elemento));
punt = punt->pun;
printf ("nInserisci il %d elemento: ", i);
scanf ("%d", &punt->inf);
}
punt->pun= NULL;
}
return (p);
}
void visualizza_lista (struct elemento *p)
{
printf ("nlista ---> ");
while (p !=NULL)
{
printf ("%d", p->inf);
printf (" ---> ");
p = p->pun;
}
printf ("NULLnn\n");
}
Quote:
scusate il disturbo grazie mille!
__________________
|Antec Nine Hundred by me~LC Titan 560W~Asus P5QD Turbo~Intel Q9550~Corsair Dominator xms2-8500~Sapphire HD5870~SB Audigy X-Fi XtremeGamer~Samsung 320Gb sataII~LG dvd-rw~2xAcer P193w + Samsung SM 2243SN~Logitech z-5300~|Notebook MSI S271| Fastweb 20Mb ~ BOINC GOD - 15 UOTD |
|
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Preparati a fare come Tafazzi...manca il punto e virgola dopo la parentisi chiusa della struct
![]() PS: grande avatar |
|
|
|
|
|
#3 | |
|
Senior Member
Iscritto dal: May 2004
Città: Pianeta Terra
Messaggi: 1593
|
Quote:
però ora l'ho messa...mi fa inserire il primo valore nella lista, poi mi dice Segmentation fault (core dumped) uffa.... Ps: Devo dire la stessa cosa del tuo avatar
__________________
|Antec Nine Hundred by me~LC Titan 560W~Asus P5QD Turbo~Intel Q9550~Corsair Dominator xms2-8500~Sapphire HD5870~SB Audigy X-Fi XtremeGamer~Samsung 320Gb sataII~LG dvd-rw~2xAcer P193w + Samsung SM 2243SN~Logitech z-5300~|Notebook MSI S271| Fastweb 20Mb ~ BOINC GOD - 15 UOTD |
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
scanf("%d", &p->inf);
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: May 2004
Città: Pianeta Terra
Messaggi: 1593
|
Vedi cionci io ti voglio bbene!!!
PS.: Faccio un tributo ai Death, se capito dalle tue parti col gruppo ti avviso e ti pago da bere!!! Grazie mille!!!!
__________________
|Antec Nine Hundred by me~LC Titan 560W~Asus P5QD Turbo~Intel Q9550~Corsair Dominator xms2-8500~Sapphire HD5870~SB Audigy X-Fi XtremeGamer~Samsung 320Gb sataII~LG dvd-rw~2xAcer P193w + Samsung SM 2243SN~Logitech z-5300~|Notebook MSI S271| Fastweb 20Mb ~ BOINC GOD - 15 UOTD |
|
|
|
|
|
#6 | |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Quote:
|
|
|
|
|
|
|
#7 | |
|
Senior Member
Iscritto dal: May 2004
Città: Pianeta Terra
Messaggi: 1593
|
Quote:
Grazie di tutto!!! il programma funziona alla perfezione
__________________
|Antec Nine Hundred by me~LC Titan 560W~Asus P5QD Turbo~Intel Q9550~Corsair Dominator xms2-8500~Sapphire HD5870~SB Audigy X-Fi XtremeGamer~Samsung 320Gb sataII~LG dvd-rw~2xAcer P193w + Samsung SM 2243SN~Logitech z-5300~|Notebook MSI S271| Fastweb 20Mb ~ BOINC GOD - 15 UOTD |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 22:22.




















