summaryrefslogtreecommitdiff
path: root/demo/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'demo/util.c')
-rw-r--r--demo/util.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/demo/util.c b/demo/util.c
index 457a32c..99566bd 100644
--- a/demo/util.c
+++ b/demo/util.c
@@ -1,3 +1,7 @@
+#include <stddef.h>
+
+#include "demo.h"
+
int strcmp(const char *s1, const char *s2)
{
while (*s1 && *s1 == *s2)
@@ -5,3 +9,24 @@ int strcmp(const char *s1, const char *s2)
return (int)*(const unsigned char *)s1 - (int)*(const unsigned char *)s2;
}
+
+char *strtok_input(char **tokens)
+{
+ char *start = *tokens;
+ while (*start && *start == ' ')
+ ++start;
+
+ if (!*start) {
+ *tokens = start;
+ return NULL;
+ }
+
+ char *end = start + 1;
+ while (*end && *end != ' ')
+ ++end;
+
+ *tokens = *end ? end + 1 : end;
+ *end = '\0';
+
+ return start;
+}