LOTS of source to look at here, basically it does everything I want it to but properly compare the values of both pointers and upon looking at their values in the debugger, when they match, its not registering as true and still defining another word for the array. RUNDOWN : This program takes a text file, and strips words out and keeps a count of how many times they were used, adds to the list if it cannot find it in the array.
*** The piece that isn't working as I would like it to, is in the Statistics.cpp file, the section for strcmp, even comparing as an if statement it does not return true under true conditions ***
int main(int argc, char *argv[])
{
char wordPtr[200] = {0}; // Value to swap around the current word
int statCount = 0; // Counter for stats entered into table
// If the number of arguments passed into the command is NOT equal to two return argument instructions
if ( argc != 2 )
{
cout << "Usage: \"Lab 13.exe\" FILENAME.EXTENTION (E.G. \"Lab 13.exe\" hamlet.txt" << endl;
return -1;
}
// File Initialization call, if fails ends program
if (myReader.initialize(argv[1]) == false)
return -1;
// Continues to loop until the end of the file is reached
while (myReader.getNextWord(wordPtr) == true)
{
myStats.addWord(wordPtr);
}
myStats.printWordCount();
return 0;
}
=============
Reader.h
=============
#include <fstream>
using namespace std;
class Reader
{
public :
bool initialize(char *filename); // Checks to see if filename is set
bool getNextWord(char * nextWord); // Gets the next word
bool Reader::getNextWord(char *nextWord)
{
char *buffer = ""; // Generate a buffer
char getWord[200] = ""; // Generate a char array for string operations
f_handle >> nextWord; // Get next word from ifstream
buffer = strtok ( nextWord, " .,';:()-!?" ); // Assign the buffer the value of next token
// Loop while tokens are being returned
while (buffer !=NULL)
{
strcat( getWord, buffer ); // Concatanate buffer into getWord
buffer = strtok ( NULL, " .,';:()-!?" ); // Get next token value
}
strcpy( nextWord, getWord ); // Copy new string into nextWord
// Check to see if the file is still active
if ( !f_handle )
return false;
else
return true;
}
bool Reader::initialize(char *filename)
{
bool checkFile;
// Load the file into memory to check
f_handle.open(filename , ios::in);
if (!f_handle)
{
cout << filename << " could not be opened" << endl;
checkFile = false;
}
else
checkFile = true;
for (int x = 0; x < m_counter; ++x)
{
cout << setw(14) << m_word[x] << setw(14) << m_wordCount[x] << endl;
}
};
=======================
Yes I do realize I seem to be making the allocation of the statistics rather rough, however its an outline for me to use if I'm unable to impliment use through an object. However the definition of the functions must stay as is and the only rule is that I can add functions at will, but have to use the ones the way they were predefined in the headers :\.... any tips would be greatly appreciated too, however I'd like to understand how come I cant properly compare the two strings and get an output of 1 value for every single word seperated...