Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. int save_dictionary_b(const struct dictionary_t *d, const char *filename)
  2. {
  3. if(!d || !filename || !d->wc || d->capacity<=0 || d->size<0 || d->size>d->capacity)
  4. return 1;
  5. FILE *f=fopen(filename, "wb");
  6. if(!f)
  7. return 2;
  8. fwrite(&(d->size), sizeof(int), 1, f);
  9. int size=d->size;
  10. for(int i=0; i<size; i++)
  11. {
  12. int len=strlen((d->wc+i)->word);
  13. fwrite(&len, sizeof(int), 1, f);
  14. fwrite(&((d->wc+i)->word), sizeof(char), len, f);
  15. fwrite(&((d->wc+i)->counter), sizeof(int), 1, f);
  16. }
  17. fclose(f);
  18. return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement