Advertisement
mario_99

Untitled

Jun 8th, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. typedef struct c{
  7.     char nome[15];
  8.     char cognome[20];
  9.     char citta[10];
  10.     int camera;
  11.     char dataIn[20];
  12.     char dataOut[20];
  13. }cliente;
  14.  
  15.  
  16. typedef struct d{
  17.     cliente info;
  18.     struct d *next;
  19. }nodo, *lista;
  20.  
  21.  
  22. int menu(){
  23.     int scelta ;
  24.     printf("\n***MENU***\n");
  25.     printf("\n1)Inserisci Ordinatamente: \n");
  26.     printf("\n2)Conteggio clienti presenti in un periodo di tempo: \n");
  27.     printf("\n3)Estrazione clienti camere: \n");
  28.     printf("\n4)estrazione utenti stessa citta: \n");
  29.     printf("\n0) premi 0 per terminare\n");
  30.     scanf("%d", &scelta);
  31.     return scelta;
  32. }
  33.  
  34. void InserisciInListaOrdinata(lista *l, cliente cl){
  35.     lista aux = NULL;
  36.  
  37.     if (*l == NULL){
  38.         aux = (lista)malloc(sizeof(nodo));
  39.         aux->info = cl;
  40.         aux->next = *l;
  41.         *l = aux;
  42.     }
  43.     else
  44.     {
  45.         if ((*l)->info.camera < cl.camera){
  46.             aux = (lista)malloc(sizeof(nodo));
  47.             aux->info = cl;
  48.             aux->next = *l;
  49.             *l = aux;
  50.         }
  51.         else{
  52.             InserisciInListaOrdinata(&(*l)->next, cl);
  53.         }
  54.  
  55.  
  56.     }
  57. }
  58.  
  59.  
  60. void Carica(lista *l, char *nomefile){
  61.     FILE*f;
  62.     cliente cl;
  63.     f = fopen(nomefile, "r");
  64.     if (f == NULL){
  65.         printf("errore apertura file");
  66.         exit(1);
  67.     }
  68.     if (l != NULL){
  69.         while (fscanf(f, "%s,%s,%s,%d,%s,%s", cl.nome, cl.cognome, cl.citta, &cl.camera, cl.dataIn, cl.dataOut) == 6){
  70.             InserisciInListaOrdinata(&(*l), cl);
  71.         }
  72.         printf("\nfile caricato\n");
  73.         fclose(f);
  74.  
  75.  
  76.     }
  77.     else {
  78.         printf("file non trovato");
  79.     }
  80. }
  81.  
  82. void presenza(lista l, char *dataIn, char *dataOut){
  83.     while (l != NULL){
  84.         if (strcmp(l->info.dataIn, dataIn) >= 0 && strcmp(l->info.dataOut, dataOut) <= 0){
  85.  
  86.             printf("il cliente %s %s era in hotel tra il %s e il %s\n", l->info.cognome, l->info.nome, l->info.dataIn, l->info.dataOut);
  87.         }
  88.         l = l->next;
  89.     }
  90.  
  91.  
  92. }
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. int main(void){
  100.     int scelta =0;
  101.     lista L ;
  102.     L = NULL;
  103.     char nomefile[15];
  104.     char dataIn[16];
  105.     char dataOut[20];
  106.     do{
  107.         scelta = menu();
  108.         switch (scelta){
  109.         case 1:{
  110.             printf("Inserisci il nome del file da caricare: \n");
  111.             scanf("%s", nomefile);
  112.             Carica(&L, nomefile);
  113.             break;
  114.         }
  115.         case 2:
  116.         {printf("\nInserisci data di arrivo: \n");
  117.         scanf("%s", dataIn);
  118.         printf("\nInserisci data di uscita: \n");
  119.         scanf("%s", dataOut);
  120.         presenza(L, dataIn, dataOut);
  121.         break; }
  122.         case 3:
  123.             break;
  124.         case 4:
  125.             break;
  126.         }
  127.  
  128.     } while (scelta != 0);
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement