Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. FILE* file = 0;
  2. char filename[25];
  3.  
  4. printf("Saving grocery list to test.bin...n");
  5.  
  6. errno_t errorCode = fopen_s(&file, "test.bin", "wb"); //This line is different
  7. //because of MVS...
  8.  
  9. if (file == NULL )
  10. {
  11. printf("File could not be opened.n");
  12. return 0;
  13. }
  14.  
  15. else
  16. {
  17. fwrite(&totalGrocery, sizeof(int), totalGrocery, file);
  18. fwrite(&item, sizeof(struct grocery), totalGrocery, file);
  19. fclose(file);
  20. printf("The file has now been saved.n");
  21. }
  22.  
  23. struct grocery
  24. {
  25. int id;
  26. char food[31];
  27. float quantity;
  28. char unit[16];
  29. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement