How to check the occurence of each words in the textfile and display the number of times C++

I have a C++ issue. Currently i have a text file that store the following data. I wish to do a simple program where it will read the data and print out the most frequent display of item and the quantity of it.

I do not wish to set an array of fixed number of words to search through the file as the item entered into the text file is not predetermined

Below are the structure of the data in the text file

The fourth value is the quantity and the second value is the item name

Text File:

1|Bag|2|3|6|20Apr2015
2|Fruit|2.3|5|11.5|20Aug2015
4|Water|0.9|5|4.5|20Jun2015
5|File|0.9|5|4.5|20Jul2015
6|Water|0.9|5|4.5|20Nov2015
7|Water|0.9|5|4.5|20May2015
8|Bag|0.9|5|4.5|20Jan2015
9|Water|0.9|5|4.5|20Feb2015
10|Water|0.9|5|4.5|20Jan2015
11|Water|0.9|5|4.5|20Dec2015
12|File|0.9|5|4.5|20Oct2015
13|Water|0.9|5|4.5|20Sep2015
14|Water|0.9|5|4.5|20Sep2015

Desired Output:

The most frequent item is Water and 40 are sold

The least frequent item is Fruit and 5 are sold


Here is my current coding

void computeItem()
{


string itemid;
float totalprice;
string item[4] ={"Water","Bag","Fruit","File"};
int itemqty[4]={};

int founditem;
int foundyear;
string year;
string found;

cout<<endl;


for(int i = 0; i < MAX- 1; i++)
{
if(transactionpile[i].itemid !="")
{
for(int k=0; k<4;k++)
{

founditem = transactionpile[i].itemdesc.find(item[k]);
if(foundmonth<transactionpile[i].itemdesc.length())
{
//Add the totalprice of each found records to totalsalesmonth[k]
itemqty[k] += transactionpile[i].quantity;

}

}


}

}


}



//Print out the output
for(int i=0; i<4; i++)
{

cout << " " << item[i] << " " << << itemqty[i] <<endl;


}

}
make it a binary structured file, and handle it with APIs like SetFilePointer()..
MapViewOfFile()...
Hi, do you have an example or reference that i can refer to , as i'm quite new to programming. And this API that you mentioned, can it work on Ubantu?
are simple Windows API functions, check out on MSDN
I think that if you plan to interact with files in your games/programs you must know the set of API functions that handle files.
so on your free time.. investigate a bit.

Topic archived. No new replies allowed.