Salve ragazzi, ho un problema nel stampare a video questo codice:
codice:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#define SIZE 80
struct element {
char name[SIZE];
char surname[SIZE];
int matnumber;
struct element *next;
};
void menu();
void list(struct element *list_head);
struct element *insert(struct element *list_head);
//struct element *sortbyname(struct element *list_head);
//struct element *sortbymatnumber(struct element *list_head);
int main () {
struct element *list_start=NULL;
int comando;
do{
menu();
printf("\nComando: ");
scanf("%d",&comando);
switch(comando) {
case 1: {
list_start=insert(list_start);
break;
}
/* case 2: {
list_start=sortbyname(list_start);
break;
}
case 3: {
list_start=sortbymatnumber(list_start);
break;
}*/
case 4: {
list(list_start);
break;
}
}
return 0;
} while(true);
}
struct element *insert(struct element *list_head){
struct element *newnode, *temp;
int x;
temp=list_head;
if (list_head!=NULL)
while(temp->next!=NULL)
temp=temp->next;
do {
newnode=(struct element*)malloc(sizeof(struct element));
/*if (newnode==NULL){
printf("ERROR");
EXIT(FAILURE_EXIT);
}*/
if(list_head==NULL) {
printf("Inserire nome:\n ");
fgets(newnode->name,SIZE,stdin);
printf("\nInserire cognome: ");
fgets(newnode->surname,SIZE,stdin);
printf("Inserire Numero matricola'");
scanf("%d",&newnode->matnumber);
newnode->next=NULL;
list_head=newnode;
temp=temp->next;
} else {
printf("Inserire nome:\n ");
fgets(newnode->name,SIZE,stdin);
printf("\nInserire cognome: ");
fgets(newnode->surname,SIZE,stdin);
printf("Inserire Numero matricola'");
scanf("%d",&newnode->matnumber);
newnode->next=NULL;
temp->next=newnode;
temp=temp->next;
}
printf("Vuoi registrare un altro studente? (premere 1 per risposta affermativa)");
scanf("%d",&x);
} while (x==1);
return list_head;
}
void menu(){
printf("|||||||||||||||||||||");
printf("\n1)Registrare studente");
printf("\n4)Visualizza lista");
printf("|||||||||||||||||||||");
}
void list (struct element *list_head) {
struct element *list_pointer =list_head;
printf("\nNOME \t COgnome \t N.Matricola ");
while(list_pointer != NULL){
printf("%s \t %s \t %d\n", list_pointer->name,list_pointer->surname,list_pointer->matnumber);
list_pointer = list_pointer->next;
}
printf("\nEND") ;
}
Non mi fa inserire il nome ma solo il cognome e il numero di matricola ma subito dopo i blocca.... come posso uscirne fuori?
grazie in anticipo.