1
0
forked from 131/lab3_test
Files
lab3_test/str_lib.c
2025-11-15 04:27:54 -05:00

40 lines
823 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <string.h>
int
mystrlen(const char *s)
{
// <YOURCODE>
int len = 0;
while (s[len] != '\0') {
len++;
}
return len;
}
int
mystr_idx(const char *s1, const char *s2)
{
// <YOURCODE>
int len1 = mystrlen(s1);
int len2 = mystrlen(s2);
if (len2 == 0) {
return 0; // Пустая строка всегда в начале
}
for (int i = 0; i <= len1 - len2; i++) {
int j;
for (j = 0; j < len2; j++) {
if (s1[i + j] != s2[j]) {
break; // Не совпадает
}
}
if (j == len2) {
return i; // Найдено полное совпадение
}
}
return -1;
}