From 48d46880eaca830b344b06119511c3b11d58b51d Mon Sep 17 00:00:00 2001 From: alexey Date: Thu, 4 Dec 2025 23:55:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=B8=D0=BB=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=B8=D0=BA=20mystrlen,=20mystr=5Fidx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- str_lib.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/str_lib.c b/str_lib.c index fa1d7db..439efd2 100644 --- a/str_lib.c +++ b/str_lib.c @@ -7,7 +7,11 @@ int mystrlen(const char *s) { - // + int len = 0; + while (s[len] != '\0') { + len++; + } + return len; } /* @@ -17,7 +21,29 @@ mystrlen(const char *s) int mystr_idx(const char *s1, const char *s2) { - // + if (s1 == NULL || s2 == NULL) + return -1; + + if (s2[0] == '\0') + return 0; + + int len1 = mystrlen(s1); + int len2 = mystrlen(s2); + + if (len2 > len1) + return -1; + + for (int i = 0; i <=len1 - len2; i++) { + int j = 0; + while (j < len2 && s1[i + j] == s2[j]) { + j++; + } + if (j == len2) + return i; + } + return -1; } + +