string_list.c

changeset 19
8bac9fd0629d
parent 17
5f43f733cc12
child 20
43725438ac50
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/string_list.c	Sun Oct 16 12:20:52 2011 +0200
@@ -0,0 +1,34 @@
+/*
+ * string_list.c
+ *
+ *  Created on: 15.09.2011
+ *      Author: beckermi
+ */
+
+#include "string_list.h"
+
+string_list_t* new_string_list_t() {
+  string_list_t* stringList = malloc(sizeof(string_list_t));
+  stringList->count = 0;
+  stringList->items = NULL;
+
+  return stringList;
+}
+
+void destroy_string_list_t(string_list_t* list) {
+  if (list->items != NULL) {
+    free(list->items);
+  }
+  free(list);
+}
+
+void add_string(string_list_t* list, char* item) {
+  char** reallocated_list =
+    realloc(list->items, sizeof(char*) * (list->count + 1));
+  if (reallocated_list != NULL) {
+    list->items = reallocated_list;
+    list->items[list->count] = item;
+    list->count++;
+  }
+}
+

mercurial