Guest User

Untitled

a guest
Jun 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include "settings.h"
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. settings_t settings;
  7.  
  8. void read_settings(void)
  9. {
  10. FILE *fd;
  11.  
  12. fd = fopen("settings", "r");
  13. if (fd == NULL) {
  14. printf("settings.c:read_settings: could not open settings\n");
  15. exit(1);
  16. }
  17.  
  18. if (!(fread(&settings, sizeof(settings_t), 1, fd))) {
  19. fclose(fd);
  20. printf("settings.c:read_settings: could not read settings\n");
  21. exit(1);
  22. }
  23.  
  24. fclose(fd);
  25. }
  26.  
  27. void write_settings(void)
  28. {
  29. FILE *fd;
  30.  
  31. fd = fopen("settings", "w");
  32. if (fd == NULL) {
  33. printf("settings.c:read_settings: could not open settings\n");
  34. exit(1);
  35. }
  36.  
  37. if (!(fwrite(&settings, sizeof(settings_t), 1, fd))) {
  38. fclose(fd);
  39. printf("settings.c:read_settings: could not write settings\n");
  40. exit(1);
  41. }
  42.  
  43. fclose(fd);
  44. }
Add Comment
Please, Sign In to add comment