Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include "container.h"
  3.  
  4.  
  5. struct container* create_container(struct container* first, enum container_type type, void* entry){
  6.    
  7. if(entry==NULL)
  8.     return NULL;
  9.  
  10. struct container* novy = (struct container*) malloc(sizeof(struct container*));
  11.  
  12. novy->next=NULL;
  13.  
  14.  
  15.     if(type==ROOM) novy->room=(struct room*) entry;
  16.         else {
  17.         free(novy);
  18.         return NULL;
  19.         }
  20.     if(type==COMMAND) novy->command=(struct command*) entry;
  21.         else {
  22.         free(novy);
  23.         return NULL;
  24.         }
  25.     if(type==ITEM) novy->item=(struct item*) entry;
  26.         else {
  27.         free(novy);
  28.         return NULL;
  29.         }
  30.     if(type==TEXT) novy->text=(char*) entry;
  31.         else {
  32.         free(novy);
  33.         return NULL;
  34.         }
  35.     if(first==NULL) return novy;
  36.         else
  37.             first->next=novy;
  38.    
  39.    
  40. return first;
  41. }
  42.  
  43. struct container* destroy_containers(struct container* first){
  44.    
  45. if(first==NULL)
  46.     return NULL;
  47.    
  48.  
  49.    struct container* current=first;
  50.    struct container* next;
  51.  
  52.  while(current != NULL){
  53.    
  54.       next=current->next;
  55.       free(current);
  56.       current=next;
  57.       }
  58.    
  59.    return NULL;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement