Here is my code. I need to let the user enter more fields, not just val. It's just a code I'm using to test lists, so, for exemple I want the user to add val, name and surname. How can I do it? Some terms are not in english but I think the overall of the code is clear.
#include <stdio.h>
#include <stdlib.h>
struct lista{
int val;
struct lista *next;
}Lista;
struct lista* crea(struct lista* head);
void stampa(struct lista* testa);
int main()
{
struct lista *head=NULL;
int insert=0;
while(1){
printf("\n *** MENU ***\n 1.Add in list\n 2.Print\n 3.Exit\n\n Input: ");
scanf("%d", &insert);
switch(insert){
case 1:
head = crea(head);
break;
case 2:
stampa(head);
break;
case 3:
exit(1);
default:
printf("\n Errore: scelta non valida!\n");
break;
}
}
return 0;
}
struct lista* crea(struct lista* head){
struct lista *nuovo=NULL; //sarà la nuova head
int valore=0;
nuovo = (struct lista*)malloc(sizeof(struct lista));
printf("\nValue: ");
scanf("%d", &valore);
nuovo->val=valore;
nuovo->next=head;
head = nuovo;
return nuovo;
};
void stampa(struct lista* head){
struct lista* temp=NULL;
temp = head;
while(temp != NULL){
printf("\nvalore: %d\n", temp->val);
temp = temp->next;
}
}