Guest User

Untitled

a guest
Nov 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #include "dbfz.h"
  5.  
  6. record new_record(char *name, char *section, char *address)
  7. {
  8. record nr;
  9. setzero(&nr,sizeof(record));
  10. sprintf(nr.name, "%s", name);
  11. sprintf(nr.address, "%s", address);
  12. sprintf(nr.section, "%s", section);
  13. return nr;
  14. }
  15.  
  16. void write_records(record array[], int num_records)
  17. {
  18. FILE *fp = fopen("file.db", "w");
  19. dbheader header;
  20. int i;
  21. sprintf(header.magic, "%s", MAGIC);
  22. header.num_records = num_records;
  23.  
  24. fwrite(&header, sizeof(dbheader), 1, fp);
  25.  
  26. for (i = 0; i < num_records; i++)
  27. {
  28. fwrite(&array[i], sizeof(record), 1, fp);
  29. }
  30.  
  31. fflush(fp);
  32. fclose(fp);
  33. }
  34.  
  35. /* Function to set chunks of memory to zero */
  36. void setzero(void *str, int size)
  37. {
  38. int i;
  39. for (i = 0; i < size; i++)
  40. {
  41. *(char*)str++ = 0;
  42. }
  43. }
Add Comment
Please, Sign In to add comment