Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int i = 0, j, counter = 0, lenStr1 = 0, lenStr2 = 0, index;
- char str1[LETTERS], str2[LETTERS];
- cout << "please enter 2 strings (max " << LETTERS - 1 << " letters): ";
- for (i = 0; i <= LINE; i++)
- cin.getline(str1, LETTERS);
- cin.getline(str2, LETTERS);
- lenStr2 = strlen(str2);
- lenStr1 = strlen(str1);
- for (i = 0, j = 0; i<lenStr1; i++)
- {
- while (str1[i] == str2[j] && counter != lenStr2)
- {
- counter++;
- if (counter == 1)
- {
- index = i;
- }
- j++;
- i++;
- }
- if (counter != lenStr2)
- {
- counter = 0;
- j = 0;
- }
- }
- if (counter == lenStr2)
- cout << "the second string found in index " << index << " at the first string\n";
- else
- cout << "\n" << -1 << "\n\n";
- system("pause");
- system("cls");
- break;
Advertisement
Add Comment
Please, Sign In to add comment