почему не работает поиск?

#include <iostream>
#include<string>
using namespace std;
int pos(char* s, char* c, int n)
{
    int i, j;       
    int lenC, lenS; 
 

    for (lenC = 0; c[lenC]; lenC++);
    for (lenS = 0; s[lenS]; lenS++);
 
    for (i = 0; i <= lenS - lenC; i++) 
    {
        for (j = 0; s[i + j] == c[j]; j++);
        if (j - lenC == 1 && i == lenS - lenC && !(n - 1)) return i;
        if (j == lenC)
            if (n - 1) n--;
            else return i;
    }
    return -1;
}
 
int main()
{
    char s[200];
    char c[200];
    string t;
    string p;
    cout << "Vvedite text" << endl;
    getline(cin, t);
    strcpy_s(s, t.c_str());
    cout << "Vvedite stroku" << endl;
    getline(cin, p);
    strcpy_s(c, p.c_str());
 
    int i, n = 0;
 
    for (i = 1; n != -1; i++)
    {
        n = pos(s, c, i);
 
        if (n >= 0)
            cout << n << endl;
    }
}

Ответы (0 шт):