I have a file A that has multiple paragraphs. I need to identify where I matched words from another file B. I need to tell the paragraph, line number, and word number of every word, including those matching a word in file B. I've finally gotten so far, having given up on vectors, and arrays, and string splitting. I learned (I think) stringstream. Currently, I read in the line, then split it on the "." into sentences, then read those sentences back in again, splitting on the " ". I have the line numbers counting, and the words counting and matching, but I just can't seem to get the paragraph numbers (I've realized that the p++ is actually counting the lines, and the l++ is counting words as well). Could someone please help me? edit Each paragraph is separated by "\n" and each sentence is separated by a "." I'll still have to figure out a way to ignore all other punctuation so that words match 100%, and are not thrown off by a comma, semi-colon, or other punctuation. I'm guessing that will be a regex in there somewhere.
input from file with the text would look like:
My dog has fleas in his weak knees. This is a line. The paragraph is ending.'\n' Fleas is a word to be matched. here is another line. The paragraph is ending.'\n'
output should look something like:
paragraph1 line 1 word 1 My paragraph1 line 1 word 2 dog paragraph1 line 1 word 3 has paragraph1 line 1 word 4 MATCHED! fleas
while (getline(fin, para)) { //get the paragraphs
pbuffer.clear();
pbuffer.str("."); //split on periods
pbuffer << para;
p++; //increase paragraph number
while (pbuffer >> line) { //feed back into a new buffer
lbuffer.clear();
lbuffer.str(" "); //splitting on spaces
lbuffer << line;
l++; //line counter
while (lbuffer >> word) { //feed back in
cout << "l " << l << " W: " << w << " " << word;
fmatch.open("match.txt");
while (fmatch >> strmatch) { //did I find a match?
if (strmatch.compare(word) == 0) {
cout << " Matched!\n";
}
else {
cout << "\n";
}
}