I wrote a program that search for substrings and prints the line starting with the substring to the end of the line. I need to add a loop that will continue to check for a occurence of the string until the complete line has been checked.
I wrote the program and also I was able to write a line that will check for the next occurence after the first but I can't figure out how to create a loop that will keep going until the entire line of text has been checked.
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
usingnamespace std;
int main()
{
char firststring[80];
char search [80];
char *searchPtr;
char *searchPtr2;
cout << "Enter the first sentence: " << endl;
cin.getline(firststring, 80, '\n');
cout << "Enter the string you are looking for: " << endl;
cin.getline(search, 80, '\n');
searchPtr = strstr(firststring, search);
cout << "String1 = " << firststring << "\nstring2 = " << search
<< "\n\nThe remainder of string1 beginning with the\n"
<< "first occurrence of string2 is: \n"
<< searchPtr << endl;
//I need the while loop here
cout << "There is another occurrence of the search string that starts here: \n"
<< strstr(searchPtr + 1, search) << endl;
return 0;
}
I using a couple of arrays so I tried to create a while loop using the size of the array but my array is 80 and the while loop keeps printing out the same last line 80 times.