Find a string within a string

The Instructions are: Your program receives from user two strings of symbols: first long one and then short one. Then your program returns all positions in long string where short string occures as a substring.
For example: long string is "aabcccbabc" and short one is "abc". Short string can be seen twice in the long string "aabcccbabc" in positions 1 and 7 (enumeration of positions in string starts as always from 0). Position of the substring is the position of its first symbol in the whole string. You are not allowed to use any built-in functions, such as strlen().
I don't know how to make this program output a position itself, and I can't get it find the matches. Please help, I'm stuck.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  #include <iostream>
using namespace std;

int main()
{
int NUM_MTCH, POSS1, POSS2, LENS1, LENS2 ;
NUM_MTCH=0;    //NUM_MTCH= THE NUMBER OF MATCHES
POSS1=0;       //POSITION OF PATTERM IN STRING2
POSS2=0;       //POSITION OF PATTERN IN STRING1
LENS1=0;       //LENGTH OF FIRST STRING
LENS2=0;       //LENGTH OF SECOND STRING
bool SUCCESS(true);
string S1, S2;
do
{
        cout<< "Enter First String: ";
        cin>> S1;
        for (POSS1=0; S1[POSS1] != '\0'; POSS1++)
        {
            LENS1++;
        }
        cout<< "Enter Second String: ";
        cin>>S2;
        for (POSS2=0; S2[POSS2] != '\0'; POSS2++)
        {
            LENS2++;
        }

}
while(LENS2>LENS1);

while (S1[POSS1] != '\0')
{
    for(POSS1=0; S1[POSS2+POSS1]==S2[POSS2]; POSS2++)
    {
        if (S1[POSS1+POSS2] == S2[POSS2])
        {
            SUCCESS==true;
        }
    }
}

while (S1[POSS1]!= '\0')
{
    if (S1[LENS2]==S2[POSS2])
    {
        NUM_MTCH++;
        if(NUM_MTCH != 0)
        {
            cout<<"POSITIONS: "<<POSS1;
            cout<<"NUMBER OF OCCURENCES: "<<NUM_MTCH;
        }
    }
}
POSS1++;
if (NUM_MTCH==0)
{
    cout<<"NOTHING";
}

return 0;
}
Topic archived. No new replies allowed.