If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Need help with reading and outputting files

Hi everyone, I have got an assignment. It is about comparing two files one file has sentences and the other abbreviations. so far i have managed to compare the abbreviations which appear in the sentence and erase punctuation linked to abbreviations.

However I am currently stuck on putting the punctuation back in when outputting the file. I am also stuck with replacing matching words in the sentences with the expanded abbreviations. Any help would be greatly appreciated. Not sure which code to show. but sentences and abbreviations are below.

NATO troops were on exercise in Aberd Capt Jones of the first div told Comdr Frank that his troops were near the E flank of the NATO forces. Complaining about the amount of Admin, Capt Jones radioed the NATO HQ asked for navigation relative to the HQ. The Captain then left.

For example the abbreviation "Aberd" in the sentence above needs to be replaced with Aberdeen from the abbreviations file. I need the last part of the abbreviation not "Aberd Aberdeen" need just "Aberdeen". Hope the info is understandable.

Re: Need help with reading and outputting files

I'm not following how punctuation applies to this problem, given the examples you provided.

If it were me, I'd create a map of the abbreviation to the unabbreviated words.. I'd parse the sentence, look up each word in the map, and replace it if it were found in the map. If you don't take out the punctuation, you don't need to put it back.

Also, your remove punctuation routine won't work if there are consecutive punctuation characters.

The words map would be initialised from your abbreviations file. Then from your sentence file for each word read find it in the word map. If the word exists in the word map, use the replacement from the map otherwise if it doesn't exist in the map use the original word.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
C, C++ Compiler: Microsoft VS2015

1) Not looping enough times
2) Looping too many times.
3) Not erasing all of the punctuations.
4) Using non-optimal methods of looping (e.g. calling length() each time in the loop).
5) Just plain old writing the loop wrong.

For 4) and 5) look at your code. You are at the same time erasing characters from str, thus making the length() shorter, but you're using str.length() as the loop terminator. Two things at once going on at the same time will lead to bugs.