From 37c15e5740705a806f33521b0bd4117b8d0a8f8d Mon Sep 17 00:00:00 2001 From: starnakin Date: Fri, 6 Sep 2024 23:08:56 +0200 Subject: [PATCH] add: strncmp --- src/string/strncmp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/string/strncmp.c diff --git a/src/string/strncmp.c b/src/string/strncmp.c new file mode 100644 index 0000000..3a91d7f --- /dev/null +++ b/src/string/strncmp.c @@ -0,0 +1,12 @@ +#include + +int strncmp(const char *s1, const char *s2, size_t n) +{ + size_t i = 0; + + if (n == 0) + return 0; + while (s1[i] == s2[i] && i < (n - 1)) + i++; + return s1[i] - s2[i]; +}