From b3555efa723d0b7101ea6989dc04492eca6b8745 Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Wed, 4 Oct 2023 00:36:34 -0600 Subject: demo: implement cli input --- demo/util.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'demo/util.c') 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 + +#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; +} -- cgit v1.2.3