summaryrefslogtreecommitdiffstats
path: root/bio/vaje/1/programi/explode.c
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-11-14 00:00:59 +0100
committersijanec <sijanecantonluka@gmail.com>2020-11-14 00:00:59 +0100
commitba067958e13d2bdb3fa95644771ee40ac13c4db2 (patch)
treee3cb1bd108d544c1f650e415fdfcad15a524ea0c /bio/vaje/1/programi/explode.c
parentnemščina delo 12. 11 (diff)
downloadsola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.tar
sola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.tar.gz
sola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.tar.bz2
sola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.tar.lz
sola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.tar.xz
sola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.tar.zst
sola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.zip
Diffstat (limited to 'bio/vaje/1/programi/explode.c')
-rw-r--r--bio/vaje/1/programi/explode.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/bio/vaje/1/programi/explode.c b/bio/vaje/1/programi/explode.c
new file mode 100644
index 0000000..094dd41
--- /dev/null
+++ b/bio/vaje/1/programi/explode.c
@@ -0,0 +1,56 @@
+#pragma once
+#include <string.h>
+char *strdup(const char *src)
+{
+ char *tmp = malloc(strlen(src) + 1);
+ if(tmp)
+ strcpy(tmp, src);
+ return tmp;
+}
+
+void explode(const char *src, const char *tokens, char ***list, size_t *len)
+{
+ if(src == NULL || list == NULL || len == NULL)
+ return;
+
+ char *str, *copy, **_list = NULL, **tmp;
+ *list = NULL;
+ *len = 0;
+
+ copy = strdup(src);
+ if(copy == NULL)
+ return;
+
+ str = strtok(copy, tokens);
+ if(str == NULL)
+ goto free_and_exit;
+
+ _list = realloc(NULL, sizeof *_list);
+ if(_list == NULL)
+ goto free_and_exit;
+
+ _list[*len] = strdup(str);
+ if(_list[*len] == NULL)
+ goto free_and_exit;
+ (*len)++;
+
+
+ while((str = strtok(NULL, tokens)))
+ {
+ tmp = realloc(_list, (sizeof *_list) * (*len + 1));
+ if(tmp == NULL)
+ goto free_and_exit;
+
+ _list = tmp;
+
+ _list[*len] = strdup(str);
+ if(_list[*len] == NULL)
+ goto free_and_exit;
+ (*len)++;
+ }
+
+
+free_and_exit:
+ *list = _list;
+ free(copy);
+}