Advertisement
tkamiten

Pset6 Load

May 22nd, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. /**
  2. * Loads a file into memory dynamically allocated on heap.
  3. * Stores address thereof in *content and length thereof in *length.
  4. */
  5. bool load(FILE* file, BYTE** content, size_t* length)
  6. {
  7. BYTE *buf = NULL;
  8. int counter = 0;
  9.  
  10. while(feof(file)==0)
  11. {
  12. fread(buf,sizeof(buf), 1, file);
  13. BYTE* store = malloc(sizeof(BYTE));
  14. *store = *buf;
  15. if(counter == 0)
  16. *content = store;
  17. counter++;
  18. }
  19.  
  20. *length = counter;
  21.  
  22. return true;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement