search, more than 1 word

Hello, i am a beginner and need some help.

i need a search function for more than one word...
i dont know how to do this.

plz help.

########

char suche[512] = "findthis"; // here i need more words to search
char *pos;

pos = strstr(line, suche);

if(pos)
{
printf("Match at %d. in Array.", pos-line+1);
//cout << pos-line << endl;
string found;
found=line;
cout << found << endl;

}
else
{
printf("Nothing found!");
}

}
cout << endl;
################


complete code:

#include <iostream>
#include <fstream>
#include <stdexcept>
#include <string.h>

using namespace std;

int main (void)
{
char line[256];

ifstream infile ("IKA_ANF.anf", ios::in);

if (!infile)
{
cout << "No File :-(" << endl;
return 1;
}

while (infile.getline (line, 256))
{


// do something
cout << line << endl;



char suche[512] = "Sven";
char *pos;

pos = strstr(line, suche);

if(pos)
{
printf("Match at %d. in Array.", pos-line+1);
//cout << pos-line << endl;
string found;
found=line;
cout << found << endl;

}
else
{
printf("Nothing found!");
}

}
cout << endl;


return 0;
}
use std::string instead of array. There isn't (normally) any benefit to use array. You can use then size_t find ( const string& str, size_t pos = 0 ) const; member function to search for the phrase you wish.
Topic archived. No new replies allowed.