Attempting to output contents of a text file

Posted 02 April 2013 - 03:55 AM

Hi guys, I am fairly new to this forum so please forgive any mistakes on my part. Anyway I am making a program that will check a text file and then compare it against a list of abbreviations and output how many abbreviations there are, the problem is is that I count the abbreviations found which were outputted and it doesn't match up with the amount in the first text file.

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 05:54 AM

it should show a list like this and say something like element " " was found " " times
Aberd
admin
approx
Austral
div
Capt
Comdr
e
HQ
m
mil
mt
n
NATO
NS
pop
s
sq
w
instead of this it just shows what is in the attached picture

mrbondysa, on 02 April 2013 - 05:50 AM, said:

it should show a list like this and say something like element " " was found " " times
Aberd
admin
approx
Austral
div
Capt
Comdr
e
HQ
m
mil
mt
n
NATO
NS
pop
s
sq
w
instead of this it just shows what is in the attached picture

Re: Attempting to output contents of a text file

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 06:13 AM

Here is the file

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.

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 06:48 AM

Post your current code, and the complete text file, since it is different than what you posted.

But note this program will only find complete matches, not partial matches. The string "HQ." is not the same as "HQ". If you want this to match then you could try reversing the order of the strings in the if statement.

Also remember C/C++ is case sensitive so if there is a difference in case it won't match.

Re: Attempting to output contents of a text file

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.
Aberd admin approx Austral div Capt Comdr e HQ m mil mt n NATO NS pop s sq w

Element Aberd was found 1 times
Element admin was found 0 times
Element approx was found 0 times
Element Austral was found 0 times
Element div was found 1 times
Element Capt was found 2 times
Element Comdr was found 1 times
Element e was found 0 times
Element HQ was found 1 times
Element m was found 0 times
Element mil was found 0 times
Element mt was found 0 times
Element n was found 0 times
Element NATO was found 3 times
Element NS was found 0 times
Element pop was found 0 times
Element s was found 0 times
Element sq was found 0 times
Element w was found 0 times
sh: 1: pause: not found