forked from 131/lab3_test
40 lines
823 B
C
40 lines
823 B
C
#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;
|
||
}
|
||
|
||
|