djelad1

Untitled

Dec 6th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. int i = 0, j, counter = 0, lenStr1 = 0, lenStr2 = 0, index;
  2. char str1[LETTERS], str2[LETTERS];
  3. cout << "please enter 2 strings (max " << LETTERS - 1 << " letters): ";
  4. for (i = 0; i <= LINE; i++)
  5. cin.getline(str1, LETTERS);
  6. cin.getline(str2, LETTERS);
  7. lenStr2 = strlen(str2);
  8. lenStr1 = strlen(str1);
  9. for (i = 0, j = 0; i<lenStr1; i++)
  10. {
  11. while (str1[i] == str2[j] && counter != lenStr2)
  12. {
  13. counter++;
  14. if (counter == 1)
  15. {
  16. index = i;
  17. }
  18. j++;
  19. i++;
  20. }
  21. if (counter != lenStr2)
  22. {
  23. counter = 0;
  24. j = 0;
  25. }
  26. }
  27. if (counter == lenStr2)
  28. cout << "the second string found in index " << index << " at the first string\n";
  29. else
  30. cout << "\n" << -1 << "\n\n";
  31. break;
  32. system("pause");
  33. system("cls");
Advertisement
Add Comment
Please, Sign In to add comment