for an array of substrings in an array of source strings

Write a program to search for an array of substrings in an array of source strings. Use variable names like needle and haystack to identify the substring array and source string array.

Be sure to include test cases that search for substrings..
"cat" and "walk"
in the following source strings

“boardwalk songs"
“catwalk"
“I like to walk on the catwalk"

HERE IS WHAT I HAVE SO FAR...
----------------------------------------------------------------------------

/*
loop over haystack, i
loop over needle, j
look for needle[j] in haystack[i]
if found.... print needle[j], haystack[i], location that needle[j] is in haystack[i]
else.. print "Not found"
*/

#include <string>
#include <iostream>
using namespace std;

int main()
{

string haystack[3]={ "boardwalk songs", "catwalk", "I like to walk on the catwalk" };
string needle[2] = { "cat", "walk" };

for ( int i=0; i < 4; i++ )
{
for ( int j=0; j < 3; j++ )
{
if ( needle[j] == haystack[i])
{
cout << needle[j] << "\n";
cout << haystack[i] << "\n";
cout << needle.substr(i, 1) << "\n";

if ( j = 1)
j = 0;
}
else
cout << needle[j] << " Not found";
if ( j = 1)
j = 0;
}
{



cout << "\n\n\n\n\n\n\t\t\t";
system ("pause");
return 0;
}
Got a question in all that un-tagged code and homework assignments you aren't supposed to have on this forum?
I know...I have tried this code and still cannot get the correct answer to have the second array to find the word cat into the haystack array and so forth...
Topic archived. No new replies allowed.