#include /** * mystrlen - Вычисляет длину строки. * @str: Указатель на строку. * * Возвращает: Длину строки. */ size_t mystrlen(const char *str) { size_t len = 0; if (str == NULL) { return 0; } while (str[len] != '\0') { len++; } return len; } /** * mystr_idx - Находит первое вхождение подстроки. * @haystack: Строка, в которой ищется подстрока. * @needle: Подстрока, которую нужно найти. * * Возвращает: Индекс первого вхождения, или -1, если не найдено. */ int mystr_idx(const char *haystack, const char *needle) { if (haystack == NULL || needle == NULL) { return -1; } if (*needle == '\0') { return 0; } size_t h_len = mystrlen(haystack); size_t n_len = mystrlen(needle); if (n_len > h_len) { return -1; } for (size_t i = 0; i <= h_len - n_len; i++) { int found = 1; for (size_t j = 0; j < n_len; j++) { if (haystack[i + j] != needle[j]) { found = 0; break; } } if (found) { return i; } } return -1; }