Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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
- void addToFile(Node *event)
- {
- FILE *pFile = fopen("agenda", "ab");
- if(pFile != NULL)
- {
- fwrite(event, sizeof(Node), 1, pFile);
- fclose(pFile);
- }
- return;
- }
- //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
- void List :: refreshFile()
- {
- Node *current = head;
- FILE *agenda = fopen("agenda", "wb");
- while(current != NULL)
- {
- fwrite(current, sizeof(Node), 1, agenda);
- current = current->next;
- }
- fclose(agenda);
- }
- //Legge gli eventi dal file e crea una lista
- void List :: readFromFile()
- {
- FILE *agenda = fopen("agenda", "rb");
- if(agenda != NULL)
- {
- while(!feof(agenda))
- {
- Node *newEvent = new Node;
- fread(newEvent, sizeof(Node), 1, agenda);
- this->pushNode(newEvent);
- }
- fclose(agenda);
- }
- else
- cout << "L'agenda e' vuota! \n";
- }
Add Comment
Please, Sign In to add comment