Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __FILESLOT_H__
- #define __FILESLOT_H__
- #include "csapp.h"
- typedef struct FILESLOT {
- char *filename;
- char *contents;
- uint32_t length;
- } FileSlot;
- #endif
- #ifndef __FILEDRAWER_H__
- #define __FILEDRAWER_H__
- #include "csapp.h"
- #include "fileslot.h"
- typedef struct FILEDRAWER {
- FileSlot* files[100];
- uint32_t drawerSize;
- } FileDrawer;
- void new_fd(FileDrawer *fd);
- uint32_t get_size(FileDrawer *fd);
- void add_file(FileDrawer *fd, FileSlot *fs);
- void rem_file(FileDrawer *fd, int index);
- int search_files(FileDrawer *fd, char *name);
- #endif
- #include "filedrawer.h"
- #include "fileslot.h"
- int main(int argc, char** argv) {
- FileDrawer *fdp = (FileDrawer*)malloc(sizeof(FileDrawer));
- new_fd(fdp);
- int i;
- while (i < 5) {
- uint32_t length = i;
- FileSlot* fsp = (FileSlot*)malloc(sizeof(FileSlot));
- fsp->filename = "file name";
- fsp->contents = "contents";
- fsp->length = length;
- add_file(fdp, fsp);
- i++;
- }
- for(i = 0; i < fdp->drawerSize; i++) {
- printf("File Name %s n", fdp->files[i]->filename);
- }
- free(fdp);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement