From 234616cc369e056db7987c8217cbee77443be97d Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Sun, 19 Dec 2021 21:21:36 -0800 Subject: Added strings --- src/lib/strings.c | 20 ++++++++++++++++++++ src/lib/strings.h | 7 +++++++ 2 files changed, 27 insertions(+) create mode 100644 src/lib/strings.c create mode 100644 src/lib/strings.h (limited to 'src/lib') diff --git a/src/lib/strings.c b/src/lib/strings.c new file mode 100644 index 0000000..8f62391 --- /dev/null +++ b/src/lib/strings.c @@ -0,0 +1,20 @@ +#include "../lib/strings.h" + +unsigned long strlen(char* s) { + unsigned long len = 0; + while (s[len] != 0) { + len += 1; + } + return len; +} + +unsigned char strcmp(char* a, char* b) { + unsigned long idx = 0; + while (a[idx] != 0 && b[idx] != 0) { + if (a[idx] != b[idx]) { + return 0; + } + idx += 1; + } + return a[idx] == b[idx]; +} diff --git a/src/lib/strings.h b/src/lib/strings.h new file mode 100644 index 0000000..61dd316 --- /dev/null +++ b/src/lib/strings.h @@ -0,0 +1,7 @@ +#ifndef LIB_STRINGS_H +#define LIB_STRINGS_H + +unsigned long strlen(char* s); +unsigned char strcmp(char* a, char* b); + +#endif -- cgit v1.2.1