-
-
Save anonymous/e50d18265657a5f5a6b3ffdff1bce1c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
typedef struct list{ | |
char name[100]; | |
int number; | |
struct list *n; | |
} List; | |
List *LoadFirst (List l, int b){ | |
List *first; | |
if (b==1){ | |
first = malloc(sizeof(l)); | |
printf("Inserisci nome \n"); | |
//gets(first->name); | |
scanf("%s", first->name); | |
printf("Inserisci numero \n"); | |
scanf("%d", &first->number); | |
first->n=NULL; | |
} | |
else if (b==0){ | |
first = NULL; | |
} | |
return (first); | |
} | |
void Load (List *first, List l){ | |
List *scroll=first; | |
while(scroll->n!=NULL){ | |
scroll = scroll->n; | |
} | |
scroll->n = malloc(sizeof(l)); | |
scroll = scroll->n; | |
printf("Inserisci nome \n"); | |
//gets(scroll->name); | |
scanf("%s", scroll->name); | |
printf("Inserisci numero \n"); | |
scanf("%d", &scroll->number); | |
scroll->n=NULL; | |
} | |
void View(List *first){ | |
printf("-->"); | |
while (first!=NULL){ | |
printf("Nome: %s ", first->name); | |
printf ("Numero: %d \n", first->number); | |
printf("-->"); | |
first = first->n; | |
} | |
printf("null \n \n"); | |
} | |
List *DeletebyName(List *first, char a[100]){ | |
List *previous, *next; | |
if (first!=NULL){ | |
next=first; | |
previous=NULL; | |
} | |
else{ | |
return 0; | |
} | |
if (strcmp(a, first->name)==0){ | |
first=first->n; | |
free(next); | |
return (first); | |
} | |
else{ | |
while(next->n!=NULL){ | |
if (strcmp(a, next->name)==0){ | |
previous->n=next->n; | |
free(next); | |
return (first); | |
} | |
else{ | |
previous=next; | |
next=next->n; | |
} | |
} | |
} | |
return (first); | |
} | |
int main() | |
{ | |
List paper; | |
int b, x, s; | |
char Name[100]; | |
List *first; | |
printf("Gestione Rubrica\n"); | |
printf("\n"); | |
printf("Nessuna rubrica trovata. Crearne una nuova? (1-Si 2-No) \n"); | |
scanf("%d", &b); | |
if (b!=1){ | |
return 0; | |
} | |
else if(b==1){ | |
first = LoadFirst(paper, b); | |
} | |
while(b==1){ | |
printf("Che cosa si desidera fare? \n"); | |
printf("\n"); | |
printf("1- Aggiungi nominativi \n"); | |
printf("2- Visualizza rubrica \n"); | |
printf("3- Rimuovi nominativo \n"); | |
scanf("%d", &s); | |
switch(s){ | |
case 1: | |
x = 1; | |
while (x==1){ | |
Load(first, paper); | |
printf("Aggiungere altri nominativi? (1-Si 2-No) \n"); | |
scanf("%d", &x); | |
} | |
break; | |
case 2: | |
View(first); | |
break; | |
case 3: | |
printf("Inserisci il nominativo da eliminare \n"); | |
scanf("%s", Name); | |
printf("%s", Name); | |
first = DeletebyName(first, Name); | |
printf("\n"); | |
printf("Nuova rubrica \n"); | |
View(first); | |
break; | |
} | |
printf("Si desidera fare altra operazione? (1- Si 2-No)\n"); | |
scanf("%d", &b); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment