Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include "container.h"
- struct container* create_container(struct container* first, enum container_type type, void* entry){
- if(entry==NULL)
- return NULL;
- struct container* novy = (struct container*) malloc(sizeof(struct container*));
- novy->next=NULL;
- if(type==ROOM) novy->room=(struct room*) entry;
- else {
- free(novy);
- return NULL;
- }
- if(type==COMMAND) novy->command=(struct command*) entry;
- else {
- free(novy);
- return NULL;
- }
- if(type==ITEM) novy->item=(struct item*) entry;
- else {
- free(novy);
- return NULL;
- }
- if(type==TEXT) novy->text=(char*) entry;
- else {
- free(novy);
- return NULL;
- }
- if(first==NULL) return novy;
- else
- first->next=novy;
- return first;
- }
- struct container* destroy_containers(struct container* first){
- if(first==NULL)
- return NULL;
- struct container* current=first;
- struct container* next;
- while(current != NULL){
- next=current->next;
- free(current);
- current=next;
- }
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement