Guest User

Untitled

a guest
May 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. //Aggiunge nel file un nuovo evento. Node e' il mio evento(data, ora, appuntamento) ovvero un nodo della //lista. "agenda" - file binario dove salvo gli eventi/nodi
  2.  
  3. void addToFile(Node *event)
  4. {
  5.     FILE *pFile = fopen("agenda", "ab");
  6.    
  7.     if(pFile != NULL)
  8.     {
  9.         fwrite(event, sizeof(Node), 1, pFile);
  10.         fclose(pFile);
  11.     }
  12.     return;
  13. }
  14.  
  15. //Rinnova il file dell'agenda dopo la modifica o la rimozione di un nodo. head e' il "root" di Braccini, se //stavi oggi attento in classe
  16.  
  17. void List :: refreshFile()
  18. {
  19.     Node *current = head;
  20.     FILE *agenda = fopen("agenda", "wb");
  21.    
  22.     while(current != NULL)
  23.     {
  24.         fwrite(current, sizeof(Node), 1, agenda);
  25.         current = current->next;
  26.     }
  27.     fclose(agenda);
  28. }
  29.  
  30. //Legge gli eventi dal file e crea una lista
  31. void List :: readFromFile()
  32. {
  33.     FILE *agenda = fopen("agenda", "rb");
  34.    
  35.     if(agenda != NULL)
  36.     {
  37.         while(!feof(agenda))
  38.         {
  39.             Node *newEvent = new Node;
  40.             fread(newEvent, sizeof(Node), 1, agenda);
  41.             this->pushNode(newEvent);
  42.         }
  43.         fclose(agenda);
  44.     }
  45.     else
  46.         cout << "L'agenda e' vuota! \n";
  47. }
Add Comment
Please, Sign In to add comment