Advertisement
deni-parvanov

saveToBinaryFIle

May 26th, 2020
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1.     FILE *fp;
  2.  
  3.     struct schoolList *current = head;
  4.  
  5.     if ((fp = fopen("data.bin", "wb")) == NULL) {
  6.         printErrorMessage(FILE_OPEN_FAILURE);
  7.     }
  8.  
  9.     while (current != NULL) {
  10.         fwrite(&current->data->id, sizeof(unsigned int), 1, fp);
  11.         fwrite(&current->data->classes, sizeof(unsigned int), 1, fp);
  12.         fwrite(&current->data->students, sizeof(unsigned int), 1, fp);
  13.         fwrite(current->data->name, sizeof(char), SCHOOL_NAME_LENGTH + 1, fp);
  14.         fwrite(current->data->director, sizeof(char), strlen(current->data->director) + 1, fp);
  15.  
  16.         current = current->next;
  17.     }
  18.  
  19.     fclose(fp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement