Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <malloc.h>
- typedef struct Psoci
- {
- char CodiceFiscale[18];
- char Nome[65];
- int Sesso;
- }Parametri;
- typedef struct SNodoSoci
- {
- Parametri InfoSoci;
- struct SNodoSoci *nextS;
- struct TNodoVincite *nextSottolista;
- }TNodoSocio,*t_lista;
- typedef struct Pvincite
- {
- char Data[16];
- float SoldiVinti;
- char CodiceFiscaleVincitore[20];
- }ParametriVincite;
- typedef struct SNodoVincite
- {
- ParametriVincite InfoVincite;
- struct SNodovincite *nextV;
- }TNodoVincite,*Sottolista;
- int fmenu();
- void carica(t_lista *list);
- void stampa(t_lista list);
- void StampaSottoLista(Sottolista lis);
- int main(void)
- {
- t_lista lista;
- Sottolista sottol;
- int scelta;
- while (scelta = fmenu())
- {
- switch (scelta)
- {
- case 1:
- {
- system("CLS");
- lista = NULL;
- carica(&lista);
- printf("File caricati correttamente.\n");
- system("pause");
- system("CLS");
- break;
- }
- case 2:
- {
- system("CLS");
- stampa(lista);
- system("pause");
- system("CLS");
- break;
- }
- case 3:
- {
- system("CLS");
- StampaSottoLista(lista->nextSottolista);
- system("pause");
- system("CLS");
- break;
- }
- case 4:
- {
- system("CLS");
- system("pause");
- system("CLS");
- break;
- }
- case 5:
- {
- system("CLS");
- system("pause");
- system("CLS");
- break;
- }
- case 6:
- {
- system("CLS");
- system("pause");
- system("CLS");
- break;
- }
- case 7:
- {
- system("CLS");
- system("pause");
- system("CLS");
- break;
- }
- case 8:
- {
- system("CLS");
- system("pause");
- system("CLS");
- break;
- }
- }
- }
- system("CLS");
- printf("Uscita...\n");
- }
- int fmenu()
- {
- int scelta;
- do
- {
- printf("1. Caricamento da file.\n");
- printf("2. Stampa della lista.\n");
- printf("3. Inserimento di un nuovo socio.\n");
- printf("4. Inserimento di una nuova vincita.\n");
- printf("5. Stampa le vincite di tutti i soci superiori ad una cifra fornita.\n");
- printf("6. Stampa della vincita media di ogni socio.\n");
- printf("7. Cancellazione di un socio (dato il codice fiscale).\n");
- printf("8. Salvataggio su file.\n");
- printf("0. Esci.\n");
- printf(">> ");
- scanf("%d", &scelta);
- }
- while (scelta < 0 || scelta>8);
- return scelta;
- }
- void carica(t_lista *list)
- {
- Parametri c;
- ParametriVincite d;
- Sottolista aux;
- FILE *f;
- FILE *g;
- t_lista paux, p, q;
- f = fopen("Socio.txt", "r");
- if (f == NULL)
- {
- printf("Errore. File inesistente.\n");
- exit(0);
- }
- while (fscanf(f, "%s\n%s\n%d", c.CodiceFiscale, c.Nome, &c.Sesso) == 3)
- {
- paux = (TNodoSocio*)malloc(sizeof(TNodoSocio));
- paux->InfoSoci = c;
- paux->nextS = NULL;
- paux->nextSottolista = NULL;
- p = q = *list;
- if (*list == NULL || strcmp(paux->InfoSoci.CodiceFiscale, p->InfoSoci.CodiceFiscale) == -1)
- {
- paux->nextS = *list;
- *list = paux;
- }
- else
- {
- p = q = *list;
- while (p != NULL && strcmp(paux->InfoSoci.CodiceFiscale, p->InfoSoci.CodiceFiscale) == 1)
- {
- q = p;
- p = p->nextS;
- }
- q->nextS = paux;
- paux->nextS = p;
- }
- g = fopen("Vincita.txt", "r");
- while (fscanf(g, "%s\n%f\n%s\n", d.Data, &d.SoldiVinti, d.CodiceFiscaleVincitore) == 3)
- {
- if (strcmp(paux->InfoSoci.CodiceFiscale, d.CodiceFiscaleVincitore) == 0)
- {
- aux = (TNodoVincite*)malloc(sizeof(TNodoVincite));
- aux->InfoVincite = d;
- aux->nextV = paux->nextSottolista;
- paux->nextSottolista = aux;
- }
- }
- }
- }
- void stampa(t_lista list)
- {
- while (list != NULL)
- {
- printf("%s\n%s\n%d\n\n", list->InfoSoci.CodiceFiscale, list->InfoSoci.Nome, list->InfoSoci.Sesso);
- list = list->nextS;
- }
- }
- void StampaSottoLista(Sottolista lis)
- {
- while (lis != NULL)
- {
- printf("%s\n%f\n%s\n", lis->InfoVincite.Data, lis->InfoVincite.SoldiVinti, lis->InfoVincite.CodiceFiscaleVincitore);
- lis = lis->nextV;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement