1
0
forked from 131/lab3_test
Files
lab3_test/str_lib.c

40 lines
823 B
C
Raw Normal View History

2023-03-25 03:58:02 +03:00
#include <string.h>
int
mystrlen(const char *s)
{
2025-11-15 04:27:54 -05:00
// <YOURCODE>
int len = 0;
while (s[len] != '\0') {
len++;
}
return len;
2023-03-25 03:58:02 +03:00
}
int
mystr_idx(const char *s1, const char *s2)
{
2025-11-15 04:27:54 -05:00
// <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;
2023-03-25 03:58:02 +03:00
}
2025-11-15 04:27:54 -05:00