allora ragazzi ho un piccolo problema con le liste, perche non capisco bene come funzionano, tra qualche giorno ho l'esame e sto diventando nervoso
il programma dovrebbe inserire delle stringhe in una lista(il codice non l'ho completato anche perche gia mi dava un sacco di errori compilando)
qualcuno mi puo dare una mano
codice:
#include <stdlib.h>
#include <stdio.h>
struct entry
{
char value[80];
struct entry *next;
};
struct lista *crea(int n)
{
struct entry *lista_start, *lista_record;
struct entry *start;
if(n=0)
{
printf("inserisci il prima stringa\n");
start=(struct entry*)malloc(sizeof(struct entry));
gets(start->value);
start->next=NULL;
lista_start=start;
}
else
{
printf("inserisci nuova stringa\n");
lista_record = (struct entry *) malloc (sizeof (struct entry));
gets(lista_record->value);
while ( lista_start->next!= NULL)
{
lista_start = lista_start->next;
}
if (lista_record->next != NULL)
{
lista_record->next = NULL;
lista_start->next=lista_record;
}
getchar();
return lista_start;
}
}
int main ()
{
struct lista *scorri;int m=0;
printf("MENU:\n"
"1-inserire\n"
"2-stampare\n"
"3-uscire\n");
int rsp;
scanf("%d", &rsp);
while(rsp!=3)
{
if(rsp=1)
{
scorri=crea(m);
m++;
}
printf("MENU:\n"
"1-inserire\n"
"2-stampare\n"
"3-uscire\n");
scanf("%d", &rsp);
}
}