string_list.c

changeset 34
fa9bda32de17
parent 33
1a2d7298bc82
child 35
35120de6ee53
equal deleted inserted replaced
33:1a2d7298bc82 34:fa9bda32de17
1 /*
2 * string_list.c
3 *
4 * Created on: 15.09.2011
5 * Author: Mike
6 */
7
8 #include "string_list.h"
9
10 string_list_t* new_string_list_t() {
11 string_list_t* stringList = malloc(sizeof(string_list_t));
12 stringList->count = 0;
13 stringList->items = NULL;
14
15 return stringList;
16 }
17
18 void destroy_string_list_t(string_list_t* list) {
19 if (list->items != NULL) {
20 free(list->items);
21 }
22 free(list);
23 }
24
25 void add_string(string_list_t* list, char* item) {
26 char** reallocated_list =
27 realloc(list->items, sizeof(char*) * (list->count + 1));
28 if (reallocated_list != NULL) {
29 list->items = reallocated_list;
30 list->items[list->count] = item;
31 list->count++;
32 }
33 }
34

mercurial