Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include "dbfz.h"
- record new_record(char *name, char *section, char *address)
- {
- record nr;
- setzero(&nr,sizeof(record));
- sprintf(nr.name, "%s", name);
- sprintf(nr.address, "%s", address);
- sprintf(nr.section, "%s", section);
- return nr;
- }
- void write_records(record array[], int num_records)
- {
- FILE *fp = fopen("file.db", "w");
- dbheader header;
- int i;
- sprintf(header.magic, "%s", MAGIC);
- header.num_records = num_records;
- fwrite(&header, sizeof(dbheader), 1, fp);
- for (i = 0; i < num_records; i++)
- {
- fwrite(&array[i], sizeof(record), 1, fp);
- }
- fflush(fp);
- fclose(fp);
- }
- /* Function to set chunks of memory to zero */
- void setzero(void *str, int size)
- {
- int i;
- for (i = 0; i < size; i++)
- {
- *(char*)str++ = 0;
- }
- }
Add Comment
Please, Sign In to add comment