What I have so far:
Code:
#include<iostream> // Required for cin, cout, and cerr.
#include<fstream> // Required for ifstream and ofstream.
#include<string> // Required for string.
using namespace std;
int main()
{
// Declare Objects.
char character;
bool text_state(true);
string infile;
string outfile;
ifstream html;
ofstream htmltext;
// Prompt user for name of input file.
cout << "Enter the name of the input file:";
cin >> infile;
// Prompt user for name of output file.
cout << "Enter name of the output file:";
cin >> outfile;
// Open files.
html.open(infile.c_str());
if(html.fail())
{
cerr << "Error opening the input file\n";
exit(1);
}
htmltext.open(outfile.c_str());
//Read first character from html file.
html.get(character);
while(html.eof())
{
//Check state
if(text_state)
{
if(character =='<') // Beginning of a tag.
text_state=false; // Change states.
else
htmltext << character; // Still text, write to file.
}
else
{
// Command state, no output required.
if(character =='>') // End of a tag.
text_state=true; // Change states.
}
// Read next character from html file.
html.get(character);
}
html.close();
htmltext.close();
return 0;
}
I need the function prototypes to sort through the text that was just parsed above and list the key words in order of frequency. I can handle the exclusion of things like "to", "the", etc. I do realise that what's up there will end up being a module and not the main function, so disregard the "int main()" for now. Also, I'm using Dev-C++ because the instructor wants us to, so no Visual Studio shortcuts/vernacular please.
E: I also know that this will end up in an array. First I need to make a list of all the key words (column a, if you will), then it needs to list how many times each of those appears (column b). I then need to take column b and apply a sorting algorithm to it to order it from most common to least common. I know the methodology. What I don't know are the commands, operators, syntax, etc. to do those steps.
Bookmarks