problema risolto ; ho commesso un errore nella gestione della lista ;
ho deciso di inserire ogni nuovo stringa solo nella coda e questo è il codice completo del programma
la funzione ricorsiva funziona
grazie
codice:
typedef struct {
char value [11] ;
struct list *next ;
} list ;
typedef list *listPtr ;
void inserisci ( listPtr *Head , char valore [] , int size , listPtr *Succ ) ;
void ricerca (listPtr headR ) ; /*funzione ricorsiva */
void printList ( listPtr headR );
int main ()
{
listPtr Testa = NULL ;
listPtr successivo = NULL ;
int chooce ;
char parola [10] ;
int numeroStringhe = 0 ;
printf ("scegli 1 per uscire o premi un tasto per cominciare \n\n" ) ;
scanf ("%d" , & chooce ) ;
while (chooce != 1 )
{
fprintf (stdout , "\n\n") ;
inserisci ( &Testa , parola , 10 , &successivo) ;
numeroStringhe++ ;
scanf ("%d" , & chooce ) ;
}
ricerca (Testa ) ;
/*printList (Testa ) ;*/
system ("PAUSE") ;
return 0 ;
}
void inserisci ( listPtr *Head , char valore [] , int size , listPtr *Succ )
{
listPtr Nuovo ;
/* situazione iniziale non ci sono nodi */
Nuovo = malloc ( sizeof ( list ) ) ;
if ( Nuovo != NULL )
{
if ( *Head == NULL )
{
*Head = Nuovo ;
/* strcpy ( Nuovo->value , valore ) ; */
fprintf (stdout , "inserisci la stringa o 1 per terminare\n") ;
gets (Nuovo->value ) ;
}
else
{
(*Succ)->next = Nuovo ;
fprintf (stdout , "inserisci la stringa o 1 per terminare\n") ;
gets ( Nuovo->value ) ;
/*strcpy ( Nuovo->value , valore ) ; */
Nuovo->next = NULL ;
}
*Succ = Nuovo ;
} /* fine if */
}
void ricerca ( listPtr headR )
{
if (headR == NULL) return;
ricerca ( headR->next);
fprintf (stdout , "%s-->\n" , headR->value ) ;
}
void printList ( listPtr headR )
{
while ( headR != NULL )
{
fprintf (stdout , "%s -->" ,headR->value );
headR = headR->next ;
}
}