string_list.c

changeset 19
8bac9fd0629d
parent 17
5f43f733cc12
child 20
43725438ac50
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/string_list.c	Sun Oct 16 12:20:52 2011 +0200
     1.3 @@ -0,0 +1,34 @@
     1.4 +/*
     1.5 + * string_list.c
     1.6 + *
     1.7 + *  Created on: 15.09.2011
     1.8 + *      Author: beckermi
     1.9 + */
    1.10 +
    1.11 +#include "string_list.h"
    1.12 +
    1.13 +string_list_t* new_string_list_t() {
    1.14 +  string_list_t* stringList = malloc(sizeof(string_list_t));
    1.15 +  stringList->count = 0;
    1.16 +  stringList->items = NULL;
    1.17 +
    1.18 +  return stringList;
    1.19 +}
    1.20 +
    1.21 +void destroy_string_list_t(string_list_t* list) {
    1.22 +  if (list->items != NULL) {
    1.23 +    free(list->items);
    1.24 +  }
    1.25 +  free(list);
    1.26 +}
    1.27 +
    1.28 +void add_string(string_list_t* list, char* item) {
    1.29 +  char** reallocated_list =
    1.30 +    realloc(list->items, sizeof(char*) * (list->count + 1));
    1.31 +  if (reallocated_list != NULL) {
    1.32 +    list->items = reallocated_list;
    1.33 +    list->items[list->count] = item;
    1.34 +    list->count++;
    1.35 +  }
    1.36 +}
    1.37 +

mercurial