compare two strings

#include <iostream>
#include <fstream>
#include <cstring>
#include <string>

using namespace std;

const int max_cpl = 250;
const int max_wpl =20;
const char* const words = " ";

int i = 0; //number for word
int w = 0; //number of stopwords
int main()
{

ifstream fin;
ifstream stopwords;
fin.open("reut2-000.sgm"); // open a file
stopwords.open("stopwords.txt");
if (!fin.good())
return 1;
if(!stopwords.good())
return 1;
// read each line of the file
while (!fin.eof())
{
// read an entire line
char buf[max_cpl];
char startword[max_cpl];
fin.getline(buf, max_cpl);
stopwords.getline(startword,max_cpl); const char* word[max_wpl] = {0};
const char* stopw[max_wpl]={0};
stopw[0]=strtok(startword,words);
word[0] = strtok(buf, words);

if (word[0] != " ")
{
for (i = 1; i < max_wpl; i++)
{
word[i] = strtok(0, words);
if (!word[i])
break;
}
}
if (word[0] == 0)
continue;

if (stopw[0] != " ")
{
for (w = 1; i < max_wpl; w++)
{
stopw[w]=strtok(0,words);
if (!stopw[w]) break;
}
}
if (word[0] == 0)
continue;

for(int k =0; k < i; k++)
{
for (int s = 0; s < w; s++) // i = #of words
{ //HELP HERE IT DOESNT COMPARE
if(stopw[s] != word[k])
{

cout << "Word[" << k << "] = " << word[k] << endl;
cout << endl;


}
}
}
}
return 0;
}
Welcome to the forum.

Please use the code format tags (in the pallet on the right) to format your code.

strtok() uses a static buffer, so you can only parse one thing at a time with it. You should consider using strtok_r() instead as you're parsing two strings simultaneously.
ok thanks for your help
Topic archived. No new replies allowed.