Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #ifndef __FILESLOT_H__
  2. #define __FILESLOT_H__
  3.  
  4. #include "csapp.h"
  5.  
  6. typedef struct FILESLOT {
  7. char *filename;
  8. char *contents;
  9. uint32_t length;
  10. } FileSlot;
  11.  
  12. #endif
  13.  
  14. #ifndef __FILEDRAWER_H__
  15. #define __FILEDRAWER_H__
  16.  
  17. #include "csapp.h"
  18. #include "fileslot.h"
  19.  
  20. typedef struct FILEDRAWER {
  21. FileSlot* files[100];
  22. uint32_t drawerSize;
  23. } FileDrawer;
  24.  
  25. void new_fd(FileDrawer *fd);
  26.  
  27. uint32_t get_size(FileDrawer *fd);
  28.  
  29. void add_file(FileDrawer *fd, FileSlot *fs);
  30.  
  31. void rem_file(FileDrawer *fd, int index);
  32.  
  33. int search_files(FileDrawer *fd, char *name);
  34.  
  35. #endif
  36.  
  37. #include "filedrawer.h"
  38. #include "fileslot.h"
  39.  
  40. int main(int argc, char** argv) {
  41. FileDrawer *fdp = (FileDrawer*)malloc(sizeof(FileDrawer));
  42. new_fd(fdp);
  43.  
  44. int i;
  45. while (i < 5) {
  46. uint32_t length = i;
  47. FileSlot* fsp = (FileSlot*)malloc(sizeof(FileSlot));
  48. fsp->filename = "file name";
  49. fsp->contents = "contents";
  50. fsp->length = length;
  51. add_file(fdp, fsp);
  52. i++;
  53. }
  54. for(i = 0; i < fdp->drawerSize; i++) {
  55. printf("File Name %s n", fdp->files[i]->filename);
  56. }
  57. free(fdp);
  58. return 1;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement