I have a little problem with my program, or maybe it is not that little, anyway here is the code:
This code is use to compare an input text file which is named as file.txt with a standard text file (Standar.txt), and see if the input file text matches with my standards, if matches then it will add an "/" after each match. But only if they are exactly the same, i.e there is a phrase "hello every one" in both texts it will write out "hello ever one/" after the process. But what I want to do is that if there is a phrase "hi, hello everyone" and in my standard I have the phrase "hello everyone" it will compared them and the write out "hi, hello everyone/". Can some one give me some clues of how can I make it work like that? Thx in advance.
Code:
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <fstream>
using std::ifstream;
using std::ofstream;
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <stdlib.h>
#include <iomanip>
#include <vector>
#define MAXLENGTH 256
int _tmain(int argc, _TCHAR* argv[])
{
char MyWord[MAXLENGTH]; //Temp array to save input file words.
char MyStandard[MAXLENGTH]; //Temp array to save the standard words list
// char *MyString;
vector<string> MyWords; // Vector to hold input file.
vector<string> Standard; // Vector to hold Text-normalization-phrases
// string FileName;
string original;
string replace;
ifstream ReadWord;
ifstream ReadStandard;
ofstream WriteWord;
// cout<<"imput file name plz"<<endl;
// cin>>FileName;
ReadWord.open("file.txt");
WriteWord.open("file.dat");
ReadStandard.open("Standard.txt");
if (!ReadStandard)
{
cerr<<"Standard text file not found."<<endl;
exit (1);
}
while(!ReadStandard.eof()) //read the file till reaches the end.
{
ReadStandard.getline(MyStandard,MAXLENGTH); // read a line from the file.(one line is a phrase)
Standard.push_back(MyStandard); //push the phrase into the vector "Standard";
} //read standard words over
ReadStandard.close(); //close the file handle;
if(!WriteWord.is_open())
{
cerr<<"couldn't create file"<<endl;
exit(1);
}
if (!ReadWord)
{
cerr<<"not found1"<<endl;
exit (1);
}
while(!ReadWord.eof())
{
ReadWord.getline(MyWord,MAXLENGTH);
MyWords.push_back(MyWord);
}
ReadWord.close();
// WriteWord.close();
for(unsigned i=0;i<MyWords.size();i++)
{
for(unsigned j=0;j<Standard.size();j++) //each MyWords compare to the Standard and see if it is in the standard vector
{
if(MyWords[i]==Standard[j]) // if it equal to one of the words in the standard vector
MyWords[i]=MyWords[i]+"/"; // add the slash to the end;
}
cout<<MyWords[i]<<endl;
i++;
}
for(unsigned j=0;j<MyWords.size();j++) // for each word in MyWords vector
{
WriteWord<<MyWords[j]<<endl; // write it to the destination file
}
WriteWord.flush(); // flush the memory to ensure all is written to the file
WriteWord.close(); // close the write file handls
return 0;
}
Comment