I have a problem with the format of my text file...The file is a list of words from the dictionary(27,000 words).
For whatever reason, when I search for a word with the following code, the search returns nothing unless I manually delete space("\n") around the word in the text file, and manually reinsert the space("\n"). There are 27,000 words, I'm not gonna do that for each word!
I don't know if any of that made sense but here is the code...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
using namespace std;
int main()
{
string line;
char line2[3] ;
strcpy(line2, "is");
char* cstr;
ifstream myfile ("/Users/appliedstatistics/Language/dict.txt");
if(myfile.is_open()){
do{
getline(myfile, line);
cstr = new char [line.size()+1];
strcpy (cstr, line.c_str());
if(!strcmp(cstr, line2)){cout << cstr << endl;}
}while(myfile.good());
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
|
I would like to either:
1. write this code to account for the "spaces" in the text file
or
2. write a code to read each line in the text file and copy that line into a new text file(which is formatted correctly)
or
3. re-format the entire text file
is it possible that the words in the file are not on different lines, even though they appear to be when the file is open...
any ideas would be great...