From b671216aa9b6fd15b6f53f5f0cb8566f2456ffe6 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 28 Aug 2021 14:33:28 +0200 Subject: [PATCH] Refactor --- lib/str.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/str.c b/lib/str.c index 0153b87..b95af7b 100644 --- a/lib/str.c +++ b/lib/str.c @@ -1,10 +1,11 @@ #include "str.h" unsigned int strlen(char* str) { - char* c; - for( c = str; *c != '\0'; c++ ) // search for end-of-string - - return (unsigned int)(c - str); // get size by delta-address + unsigned int len = 0; + for( char* c = str; *c != '\0'; c++ ) // search for end-of-string + len++; + + return len; } char* strcat(char* buf, char* str) { @@ -20,5 +21,7 @@ char* strcat(char* buf, char* str) { cc++; } + *(buf + bufferlen + cc) = '\0'; // add end-of-string + return buf; }