hello,
am doing a project for my school . am asked to ,
1. open a file
2. tokensise the contents and then change the case of all the letters to lower case
3. search for all the words in tat file with another file
so there are 2 files one contails the file that is tokenised and the other a list of words (like a database) .
i need to search that database for all the words in the file that ve tokenised
the program i ve written is in c++ . am having a few problems with matching . can someone pls help
#include<iostream.h>
#include<string.h>
#include<fstream.h>
#include<conio.h>
main()
{
// opening a file for reading
ifstream in ("d:/programming/text.txt");
if(!in)
{
cout<<"cannot open text \n";
return 0;
}
char line[80];
char* p;
//opening a file for writing
ofstream out("d:/programming/match.txt");
if(!out){
cout<<"cannot open match";
return 1;
}
do{
in.getline(line,80);//getting the line from the file to be read
p=strtok(line," " );//tokenising the file
while(p){
out<<p<<"\n";//putting all the tokens in the file for writing
p=strtok(NULL," ");
}
}while (in);
out.close();
in.close();
char line1[80];
char line2[80];
bool eof();
ifstream in1 ("d:/programming/whitelist.txt");
if(!in1)
{
cout<<"cannot open whitelist \n";
return 1;
}
ifstream in2 ("d:/programming/match.txt");
if(!in2)
{
cout<<"cannot open match \n";
return 0;
}
do{
in1.getline(line1,80);// get the tokens from the file
cout<<"line1="<<line1<<"\n";
do{
in2.getline(line2,80); // get the token from the data base
cout<<"line2="<<line2<<"\n";
int p1=strcmp(line1,line2);//compare
if(p1==0)
{
cout<<"match \n";
}
else{cout<<"no \n";}
}while (in2 );
cout<<"over\n";
}while (in1 );
in1.close();
in2.close();
getch();
return 0;
}