int main( int argc, char *argv[] )
{

==> This function has over 60 lines.
You need to split it into smaller functions


Everytime I try to split it up I just cause errors (it compiles but locks up when I run it through the test system so I think I'm doing something wrong). If anyone could have a look at it I would appreciate it.

#include <iostream>
#include <string>
#include <fstream>

#include "bintree.h"

using namespace std;

class word
{
   public:

   word();
   int getCount() { return count; }
   const char *getWord() const { return sWord.c_str(); }

   void setWord( const char* word )
   {
      sWord = word;
      buildPrintString();
   }

   void setCount( int n )
   {
      count = n;
      buildPrintString();
   }

   bool operator== (const word& wrd ) const
   {

      return !sWord.compare( wrd.getWord() );
   }

   bool operator< (word &wrd ) const
   {
      return ( sWord.compare( wrd.getWord() ) < 0 );
   }

   const char *toString() const
   {
      return printStr.c_str();
   }

   private:
   string sWord;
   string printStr;
   int count;

   void buildPrintString()
   {
      char count[10];

      sprintf( count, "%d", this->count );
      printStr = "  ";
      if ( this->count < 9 )
         printStr += " ";
      printStr += count;
      printStr += "  | " + sWord;
   }
};

word::word()

{
   count = 0;
}

int main( int argc, char *argv[] )
{
   if ( argc < 2 )
   {
      cout<<"ERROR - Incorrect number of arguments"<endl;
      cout<<"Syntax : wordcount filename"<<endl<<endl;
      return 0;
   }

   ifstream file( argv[1] );
   if ( !file.is_open() )
   {
      cout<<"ERROR - Unable to access "<<argv[1]<<endl;
      return 0;
   }

   int totalWords = 0, uniqueWords = 0;
   bintree<word> tree;

   while ( !file.eof() )
   {
      char buff[256];

      file.getline( buff, 226 );

      char *newword = strtok( buff, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );

      while ( newword )
      {
         // strip any word of double quotes
         string strWord = newword;
         size_t found;

         found = strWord.find_first_of("\"");
         while ( found != string::npos )
         {
            strWord.erase( found, 1 );
            found = strWord.find_first_of( "\"", found+1 );
         }

         if ( strWord.length() < 1 )
         {
            newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
            continue;
         }

         word temp;

         temp.setWord( strWord.c_str() );

         word *find = tree.find( temp );

         // Not in tree, means first occurence of the word
         if ( !find )
         {
            temp.setCount( 1 );
            tree.insert( temp );
            uniqueWords++;
         }
         else
         {
            find->setCount( find->getCount() + 1 );
         }

         totalWords++;

         newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
      }
   }

   cout<<"\nfilename : "<<argv[1]<<endl<<endl;

   cout<<"COUNT | WORD"<<endl;
   cout<<"------+------"<<endl;
   tree.print();

   cout<<endl;

   cout<<"Number of unique words in "<<argv[1]<<" is "<<uniqueWords<<endl;
   cout<<"Total number of words in "<<argv[1]<<" is  "<<totalWords<<endl;

   return 0;
}

This is my attempt, it compiles but when I go to run it it just locks up and doesn't run and I can't use global variables.

#include <iostream>
#include <string>
#include <fstream>

#include "bintree.h"

using namespace std;

int main(int, char**);
void checkWords();
void printWords();

class word
{
   public:

   word();
   int getCount() { return count; }
   const char *getWord() const { return sWord.c_str(); }

   void setWord( const char* word )
   {
      sWord = word;
      buildPrintString();
   }

   void setCount( int n )
   {
      count = n;
      buildPrintString();
   }

   bool operator== (const word& wrd ) const
   {

      return !sWord.compare( wrd.getWord() );
   }

   bool operator< (word &wrd ) const
   {
      return ( sWord.compare( wrd.getWord() ) < 0 );
   }

   const char *toString() const
   {
      return printStr.c_str();
   }

   private:
   string sWord;
   string printStr;
   int count;

   void buildPrintString()
   {
      char count[10];

      sprintf( count, "%d", this->count );
      printStr = "  ";
      if ( this->count < 9 )
         printStr += " ";
      printStr += count;
      printStr += "  | " + sWord;
   }
};

word::word()
{
   count = 0;
}

int main( int argc, char *argv[] )
{
   if ( argc < 2 )
   {
      cout<<"ERROR - Incorrect number of arguments"<<endl;
      cout<<"Syntax : wordcount filename"<<endl<<endl;
      return 0;
   }

   ifstream file( argv[1] );
   if ( !file.is_open() )
   {
      cout<<"ERROR - Unable to access "<<argv[1]<<endl;
      return 0;
   }

   checkWords();

   return 0;
}

void checkWords()
{
   int totalWords = 0, uniqueWords = 0;
   char *argv[1];
   bintree<word> tree;
   ifstream file( argv[1] );

   while ( !file.eof() )
   {
      char buff[256];

      file.getline( buff, 226 );

      char *newword = strtok( buff, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );

      while ( newword )
      {
         // strip any word of double quotes
         string strWord = newword;
         size_t found;

         found = strWord.find_first_of("\"");
         while ( found != string::npos )
         {
            strWord.erase( found, 1 );
            found = strWord.find_first_of( "\"", found+1 );
         }

         if ( strWord.length() < 1 )
         {
            newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
            continue;
         }

         word temp;

         temp.setWord( strWord.c_str() );

         word *find = tree.find( temp );

         // Not in tree, means first occurence of the word
         if ( !find )
         {
            temp.setCount( 1 );
            tree.insert( temp );
            uniqueWords++;
         }
         else
         {
            find->setCount( find->getCount() + 1 );
         }

         totalWords++;
         newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
      }
   }

      printWords();
}

void printWords()
{
   int totalWords;
   int uniqueWords;
   char *argv[1];
   bintree<word> tree;

   cout<<endl<<"filename : "<<argv[1]<<endl<<endl;

   cout<<"COUNT | WORD"<<endl;
   cout<<"------+------"<<endl;
   tree.print();

   cout<<endl;

   cout<<"Number of unique words in "<<argv[1]<<" is "<<uniqueWords<<endl;
   cout<<"Total number of words in "<<argv[1]<<" is  "<<totalWords<<endl;
}

in your revised set of code, try removing the following line:

int main(int, char**);

and what global variables are you referring to?

Removing that line makes no difference, the program still locks and doesn't run properlly.

I am saying I'm not allowed to use global variables in trying to get the program to run properlly thats all. I haven't used any in the code supplied.

you might want to consider breaking off much smaller parts of your code. for example

if ( argc < 2 )
   {
      cout<<"ERROR - Incorrect number of arguments"<endl;
      cout<<"Syntax : wordcount filename"<<endl<<endl;
      return 0;
   }

into

bool CheckArgs(int argc)
{
if ( argc < 2 )
   {
      cout<<"ERROR - Incorrect number of arguments"<endl;
      cout<<"Syntax : wordcount filename"<<endl<<endl;
      return true;
   }
 return false;
}

and in your code use

if(CheckArgs(argc))return 0;

That's five or so lines you've got out of main. Keep doing little things like that, I'm writing a game engine at the moment and my WinMain contains about ten lines.
If you really wanted to cheat you could move EVERYTHING out of main into a function and pass it the argc and argv.

MASSIVE CHEAT

void MyMainFunction( int argc, char *argv[] );
Main( int argc, char *argv[] )
{
MyMainFunction(argc,argv);
return 0;
}
void MyMainFunction( int argc, char *argv[] )
{
   if ( argc < 2 )
   {
      cout<<"ERROR - Incorrect number of arguments"<endl;
      cout<<"Syntax : wordcount filename"<<endl<<endl;
      return 0;
   }

   ifstream file( argv[1] );
   if ( !file.is_open() )
   {
      cout<<"ERROR - Unable to access "<<argv[1]<<endl;
      return 0;
   }

   int totalWords = 0, uniqueWords = 0;
   bintree<word> tree;

   while ( !file.eof() )
   {
      char buff[256];

      file.getline( buff, 226 );

      char *newword = strtok( buff, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );

      while ( newword )
      {
         // strip any word of double quotes
         string strWord = newword;
         size_t found;

         found = strWord.find_first_of("\"");
         while ( found != string::npos )
         {
            strWord.erase( found, 1 );
            found = strWord.find_first_of( "\"", found+1 );
         }

         if ( strWord.length() < 1 )
         {
            newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
            continue;
         }

         word temp;

         temp.setWord( strWord.c_str() );

         word *find = tree.find( temp );

         // Not in tree, means first occurence of the word
         if ( !find )
         {
            temp.setCount( 1 );
            tree.insert( temp );
            uniqueWords++;
         }
         else
         {
            find->setCount( find->getCount() + 1 );
         }

         totalWords++;

         newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
      }
   }

   cout<<"\nfilename : "<<argv[1]<<endl<<endl;

   cout<<"COUNT | WORD"<<endl;
   cout<<"------+------"<<endl;
   tree.print();

   cout<<endl;

   cout<<"Number of unique words in "<<argv[1]<<" is "<<uniqueWords<<endl;
   cout<<"Total number of words in "<<argv[1]<<" is  "<<totalWords<<endl;
}

Though I'm guessing this is for a collage assignment or something, thus they might consider that a fail

void checkWords()
{
    int totalWords = 0, uniqueWords = 0;
    char *argv[1];
    bintree<word> tree;

    ifstream file( argv[1] );

you are trying to use the argument passed to main, but all you are doing is creating a new variable with the same name (but with a different scope and completely different value). Try passing your 'argv' variable from main into your checkWords function.

void checkWord(char *argv[]);

Also, are you able to pinpoint where it locks up?

These are the two attached files that are called:

#ifndef BINTREE_H_
#define BINTREE_H_

#include <stdexcept>
#include <math.h>

#include "binnode.h"

/********************************************************\
   template class for a binary tree
\********************************************************/
      

template <typename dataType> class bintree
{  
   private:
      binNode<dataType> *root;
      int numItems;
      
   public:
      /*******************************************************\
         constructors & destructors
      \*******************************************************/
      
      // constructor
      bintree() : root(NULL), numItems(0) {}
      
      // destructor
      ~bintree() {
         if (root != NULL) delete root;
      }
      
      /*******************************************************\
         misc functions
      \*******************************************************/
      
      bool empty() const {
         return (numItems == NULL);
      }
      
      int size() const {
         return numItems;
      }
      
      int numNodes() const {
         if (root == NULL) {
            return 0;
         } else {
            return root->numNodes();
         }
      }
      
      int maxTreeDepth() const {
         if (root == NULL) {
            return 0;
         } else {
            return root->maxTreeDepth();
         }
      }
      
      int numLeafNodes() const {
         if (root == NULL) {
            return 0;
         } else {
            return root->numLeafNodes();
         }
      }
      
      double balance() const {
         // Returns a measure of how balanced a tree is.
         // A value of 1 is a prefectly balanced tree.
         // The closer to 0 the value is the more unbalanced
         // the tree.
         // A value < 0.5 indicates a tree that is seriously unbalanced
         
         // case of no nodes in tree
         if (numItems == 0) return 1.0;
         
         // calculate balance
         double log2numItems = log10(numItems + 1) / log10(2);
         return log2numItems / maxTreeDepth() * (numLeafNodes() * 2) / (numItems + 1); 
      }
      
      void rebalance() {
         // Rebalance tree using the AVL algorithm
         // While this does not guarantee a perfectly balanced tree
         // it does make it mostly balanced by guranteeing that the diference
         // in depth between every right and left subtree is at most 1
         
         if (root != NULL) {
            while (root->rebalance(root));
         }
      }
      
      /*******************************************************\
         insertion and erasure functions
      \*******************************************************/
      
      void insert(const dataType& newData) {
         if (root == NULL) {
            root = new binNode<dataType>(newData);
         } else {
            root->insert(newData);
         }
         numItems++;
      }
      
      void erase(const dataType& delData) {
      
         if (root == NULL) {
            throw std::invalid_argument("data does not exist in tree to erase");
         }
         
         root->erase(&root, delData);
         
         numItems--;
      }
      
      dataType* find(const dataType &findData) const {
         if (root == NULL) return NULL;
         else return root->find(findData);
      }
	  
      /*******************************************************\
         print function for assignment. 
		 assumes dataType has print() function 
      \*******************************************************/
	  
	  void print() const {
	     if (root != NULL) root->print();
      }
};

#endif
#ifndef BINNODE_H
#define BINNODE_H

#include <math.h>
#include <iostream> 

/********************************************************\
   template node class for binary tree
\********************************************************/

template <typename dataType> class binNode 
{
   private:
      dataType nodeData;
      binNode<dataType> *left, *right;
      
      void deleteNode(binNode<dataType> **root) {
         if (left == NULL && right == NULL) {
            // leaf node
            *root = NULL;
         } else if (left == NULL) {
            // right branch but no left branch
            *root = right;
         } else if (right == NULL) {
            // left branch but no right branch
            *root = left;
         } else {
            // has left and right branch
            binNode<dataType> *temp = right;
            // find left most node of right branch
            while (temp->left != NULL) temp = temp->left;
            // attach left branch to left side of right branch
            temp->left = left;
            // make root point to right branch
            *root = right;
         }
         left = NULL;
         right = NULL;
         delete (this); 
      }
           
   public:
      // constructors
      binNode() : left(NULL), right(NULL) {
      }
   
      binNode(const dataType& dataItem) :
         nodeData(dataItem), left(NULL), right(NULL) {
      }
   
      // destructor
      ~binNode() {
         if (left != NULL) delete left;
         if (right != NULL) delete right;
      }
   
      void insert(const dataType& dataItem) {
         if (nodeData == dataItem) {
            throw std::invalid_argument("dataItem already in tree");
         }
      
         if (dataItem < nodeData) {
            if (left == NULL) {
               left = new binNode(dataItem);
            } else {
               left->insert(dataItem);
            }
         } else {
            if (right == NULL) {
               right = new binNode(dataItem);
            } else {
               right->insert(dataItem);
            }
         }
      }
      
      void erase(binNode<dataType> **root, const dataType &delData) {
         if (delData == nodeData) {
            deleteNode(root);
         } else {
            if (delData < nodeData) {
               if (left == NULL) {
                  throw std::invalid_argument("delItem not in tree");
               } else {
                  left->erase(&left, delData);
               }
            } else {
               if (right == NULL) {
                  throw std::invalid_argument("delItem not in tree");
               } else {
                  right->erase(&right, delData);
               }
            }
         }
      }
      
      dataType* find(const dataType &findData) {
         if (findData == nodeData) {
            return &nodeData;
         } else if (findData < nodeData) {
            if (left == NULL) return NULL;
            else return left->find(findData);
         } else {
            if (right == NULL) return NULL;
            else return right->find(findData);
         }
      }
      
      bool rebalance(binNode<dataType>* &root) {
         int rdepth=0, ldepth=0;
         bool rotate = false;
            
         if (left != NULL) {
            if (left->rebalance(left)) rotate = true;
            ldepth = left->maxTreeDepth();
         }
         if (right != NULL) {
            if (right->rebalance(right)) rotate = true;
            rdepth = right->maxTreeDepth();
         }
             
         if (rdepth > ldepth+1) {
            // rotate anitclockwise
            root = right;
            right = right->left;
            root->left = this;
            rotate = true;
         }
         else if (ldepth > rdepth+1) {
            // rotate clockwise
            root = left;
            left = left->right;
            root->right = this;
            rotate = true;
         }
         return rotate;
      }
      
      // tree statistic functions
      int maxTreeDepth() const {
         int rdepth = 0, ldepth = 0;
         
         if (left != NULL) ldepth = left->maxTreeDepth();
         if (right != NULL) rdepth = right->maxTreeDepth();
         
         if (ldepth > rdepth) return 1 + ldepth;
         else return 1 + rdepth;
      }
      
      int numNodes() const {
         int size = 1;
         
         if (left != NULL) size += left->numNodes();
         if (right != NULL) size += right->numNodes();
         
         return size;
      }
	  
	  void print() const {
	     if (left != NULL) left->print();
		 std::cout << nodeData.toString() << "\n";
		 if (right != NULL) right->print();
      }
      
      int numLeafNodes() const {
         if (left == NULL && right == NULL) return 1;
         
         int numLeaf = 0;
         if (left != NULL) numLeaf += left->numLeafNodes();
         if (right != NULL) numLeaf += right->numLeafNodes();
         return numLeaf;
      }
      
      // overloaded dereference operator
      const dataType& operator * () const {
         return nodeData;
      }
};

#endif

Jessb - I tried that but now it doesn't compile?

#include <iostream>
#include <string>
#include <fstream>

#include "bintree.h"

using namespace std;

int main(int, char**);
void checkWords(char**);
void printWords(char**);

class word
{
   public:

   word();
   int getCount() { return count; }
   const char *getWord() const { return sWord.c_str(); }

   void setWord( const char* word )
   {
      sWord = word;
      buildPrintString();
   }

   void setCount( int n )
   {
      count = n;
      buildPrintString();
   }

   bool operator== (const word& wrd ) const
   {

      return !sWord.compare( wrd.getWord() );
   }

   bool operator< (word &wrd ) const
   {
      return ( sWord.compare( wrd.getWord() ) < 0 );
   }

   const char *toString() const
   {
      return printStr.c_str();
   }

   private:
   string sWord;
   string printStr;
   int count;

   void buildPrintString()
   {
      char count[10];

      sprintf( count, "%d", this->count );
      printStr = "  ";
      if ( this->count < 9 )
         printStr += " ";
      printStr += count;
      printStr += "  | " + sWord;
   }
};

word::word()
{
   count = 0;
}

int main( int argc, char *argv[] )
{
   if ( argc < 2 )
   {
      cout<<"ERROR - Incorrect number of arguments"<<endl;
      cout<<"Syntax : wordcount filename"<<endl<<endl;
      return 0;
   }

   ifstream file( argv[1] );
   if ( !file.is_open() )
   {
      cout<<"ERROR - Unable to access "<<argv[1]<<endl;
      return 0;
   }

   checkWords(argv[1]);

   return 0;
}

void checkWords(char *argv[] )
{
   int totalWords = 0, uniqueWords = 0;
   bintree<word> tree;
   ifstream file( argv[1] );

   while ( !file.eof() )
   {
      char buff[256];

      file.getline( buff, 226 );

      char *newword = strtok( buff, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );

      while ( newword )
      {
         // strip any word of double quotes
         string strWord = newword;
         size_t found;

         found = strWord.find_first_of("\"");
         while ( found != string::npos )
         {
            strWord.erase( found, 1 );
            found = strWord.find_first_of( "\"", found+1 );
         }

         if ( strWord.length() < 1 )
         {
            newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
            continue;
         }

         word temp;

         temp.setWord( strWord.c_str() );

         word *find = tree.find( temp );

         // Not in tree, means first occurence of the word
         if ( !find )
         {
            temp.setCount( 1 );
            tree.insert( temp );
            uniqueWords++;
         }
         else
         {
            find->setCount( find->getCount() + 1 );
         }

         totalWords++;
         newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
      }
   }

      printWords(argv[1]);
}

void printWords(char *argv[] )
{
   int totalWords;
   int uniqueWords;
   bintree<word> tree;

   cout<<endl<<"filename : "<<argv[1]<<endl<<endl;

   cout<<"COUNT | WORD"<<endl;
   cout<<"------+------"<<endl;
   tree.print();

   cout<<endl;

   cout<<"Number of unique words in "<<argv[1]<<" is "<<uniqueWords<<endl;
   cout<<"Total number of words in "<<argv[1]<<" is  "<<totalWords<<endl;
}

looks like you're passing the wrong types to the function (in your implementation). Here's your declaration:

void checkWords(char**); //or void checkWords(char *blah[])

however in your implementation you are only passing it a single char* (not char* array or char**)

checkWords(argv[1]);

Solutions:
A) change your declarations to 'void checkWords(char*);' so that the types will match, or
B) pass your entire argv into the function 'checkWords(argv)'

hope that's the issue, if it's not could you post the compiler output?

Undefined first referenced
symbol in file
printWords(char*) /var/tmp//ccGN4BSu.o
checkWords(char*) /var/tmp//ccGN4BSu.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

#include <iostream>
#include <string>
#include <fstream>

#include "bintree.h"

using namespace std;

int main(int, char**);
void checkWords(char*);
void printWords(char*);

class word
{
   public:

   word();
   int getCount() { return count; }
   const char *getWord() const { return sWord.c_str(); }

   void setWord( const char* word )
   {
      sWord = word;
      buildPrintString();
   }

   void setCount( int n )
   {
      count = n;
      buildPrintString();
   }

   bool operator== (const word& wrd ) const
   {

      return !sWord.compare( wrd.getWord() );
   }

   bool operator< (word &wrd ) const
   {
      return ( sWord.compare( wrd.getWord() ) < 0 );
   }

   const char *toString() const
   {
      return printStr.c_str();
   }

   private:
   string sWord;
   string printStr;
   int count;

   void buildPrintString()
   {
      char count[10];

      sprintf( count, "%d", this->count );
      printStr = "  ";
      if ( this->count < 9 )
         printStr += " ";
      printStr += count;
      printStr += "  | " + sWord;
   }
};

word::word()
{
   count = 0;
}

int main( int argc, char *argv[] )
{
   if ( argc < 2 )
   {
      cout<<"ERROR - Incorrect number of arguments"<<endl;
      cout<<"Syntax : wordcount filename"<<endl<<endl;
      return 0;
   }

   ifstream file( argv[1] );
   if ( !file.is_open() )
   {
      cout<<"ERROR - Unable to access "<<argv[1]<<endl;
      return 0;
   }

   checkWords(argv[1]);

   return 0;
}

void checkWords(char *argv[] )
{
   int totalWords = 0, uniqueWords = 0;
   bintree<word> tree;
   ifstream file( argv[1] );

   while ( !file.eof() )
   {
      char buff[256];

      file.getline( buff, 226 );

      char *newword = strtok( buff, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );

      while ( newword )
      {
         // strip any word of double quotes
         string strWord = newword;
         size_t found;

         found = strWord.find_first_of("\"");
         while ( found != string::npos )
         {
            strWord.erase( found, 1 );
            found = strWord.find_first_of( "\"", found+1 );
         }

         if ( strWord.length() < 1 )
         {
            newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
            continue;
         }

         word temp;

         temp.setWord( strWord.c_str() );

         word *find = tree.find( temp );

         // Not in tree, means first occurence of the word
         if ( !find )
         {
            temp.setCount( 1 );
            tree.insert( temp );
            uniqueWords++;
         }
         else
         {
            find->setCount( find->getCount() + 1 );
         }

         totalWords++;
         newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
      }
   }

      printWords(argv[1]);
}

void printWords(char *argv[] )
{
   int totalWords;
   int uniqueWords;
   bintree<word> tree;

   cout<<endl<<"filename : "<<argv[1]<<endl<<endl;

   cout<<"COUNT | WORD"<<endl;
   cout<<"------+------"<<endl;
   tree.print();

   cout<<endl;

   cout<<"Number of unique words in "<<argv[1]<<" is "<<uniqueWords<<endl;
   cout<<"Total number of words in "<<argv[1]<<" is  "<<totalWords<<endl;
}
void checkWords(char*);
void printWords(char*);

void checkWords(char *argv[] )
{
}

void printWords(char *argv[] )
{
}

you forgot to change both declarations of the functions, so the compiler is looking for checkWords(char*) but you only had checkWords(char**).

try:

void checkWords(char*);
void printWords(char*);

void checkWords(char *argv )
{
    //etc
}

void printWords(char *argv )
{
    //etc
}

By making that change I got

In function 'void checkWords(char*)':
main3.cpp:97: error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(char&)'
/opt/csw/gcc4/lib/gcc/sparc-sun-solaris2.8/4.0.2/../../../../include/c++/4.0.2/fstream:442: note: candidates are: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>] <near match>
/opt/csw/gcc4/lib/gcc/sparc-sun-solaris2.8/4.0.2/../../../../include/c++/4.0.2/fstream:428: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>]
/opt/csw/gcc4/lib/gcc/sparc-sun-solaris2.8/4.0.2/../../../../include/c++/4.0.2/iosfwd:89: note: std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&)
main3.cpp:149: error: invalid conversion from 'char' to 'char*'

So the below code now runs, the problem is that where it was outputting and calculating originally it no longer does.

#include <iostream>
#include <string>
#include <fstream>

#include "bintree.h"

using namespace std;

int main(int, char**);
void checkWords(int, char**);
void printWords(int, char**);

class word
{
   public:

   word();
   int getCount() { return count; }
   const char *getWord() const { return sWord.c_str(); }

   void setWord( const char* word )
   {
      sWord = word;
      buildPrintString();
   }

   void setCount( int n )
   {
      count = n;
      buildPrintString();
   }

   bool operator== (const word& wrd ) const
   {

      return !sWord.compare( wrd.getWord() );
   }

   bool operator< (word &wrd ) const
   {
      return ( sWord.compare( wrd.getWord() ) < 0 );
   }

   const char *toString() const
   {
      return printStr.c_str();
   }

   private:
   string sWord;
   string printStr;
   int count;

   void buildPrintString()
   {
      char count[10];

      sprintf( count, "%d", this->count );
      printStr = "  ";
      if ( this->count < 9 )
         printStr += " ";
      printStr += count;
      printStr += "  | " + sWord;
   }
};

word::word()
{
   count = 0;
}

int main( int argc, char *argv[] )
{
   if ( argc < 2 )
   {
      cout<<"ERROR - Incorrect number of arguments"<<endl;
      cout<<"Syntax : wordcount filename"<<endl<<endl;
      return 0;
   }

   ifstream file( argv[1] );
   if ( !file.is_open() )
   {
      cout<<"ERROR - Unable to access "<<argv[1]<<endl;
      return 0;
   }

   checkWords(argc, argv);
   printWords(argc, argv);

   return 0;
}

void checkWords( int argc, char *argv[] )
{
   int totalWords = 0, uniqueWords = 0;
   bintree<word> tree;
   ifstream file( argv[1] );

   while ( !file.eof() )
   {
      char buff[256];

      file.getline( buff, 226 );

      char *newword = strtok( buff, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );

      while ( newword )
      {
         // strip any word of double quotes
         string strWord = newword;
         size_t found;

         found = strWord.find_first_of("\"");
         while ( found != string::npos )
         {
            strWord.erase( found, 1 );
            found = strWord.find_first_of( "\"", found+1 );
         }

         if ( strWord.length() < 1 )
         {
            newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
            continue;
         }

         word temp;

         temp.setWord( strWord.c_str() );

         word *find = tree.find( temp );

         // Not in tree, means first occurence of the word
         if ( !find )
         {
            temp.setCount( 1 );
            tree.insert( temp );
            uniqueWords++;
         }
         else
         {
            find->setCount( find->getCount() + 1 );
         }

         totalWords++;
         newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
      }
   }
}

void printWords( int argc, char *argv[] )
{
   int totalWords;
   int uniqueWords;
   bintree<word> tree;

   cout<<endl<<"filename : "<<argv[1]<<endl<<endl;

   cout<<"COUNT | WORD"<<endl;
   cout<<"------+------"<<endl;
   tree.print();

   cout<<endl;

   cout<<"Number of unique words in "<<argv[1]<<" is "<<uniqueWords<<endl;
   cout<<"Total number of words in "<<argv[1]<<" is  "<<totalWords<<endl;
}

I've tried as below but get the following compile errors:

main3.cpp:11: error: ISO C++ forbids declaration of 'parameter' with no type
main3.cpp: In function 'void checkWords(int, char**)':
main3.cpp:149: error: cannot convert 'bintree<word>' to 'int' for argument '5' to 'void printWords(int, char**, int, int, int)'

#include <iostream>
#include <string>
#include <fstream>

#include "bintree.h"

using namespace std;

int main(int, char**);
void checkWords(int, char**);
void printWords(int, char**, int, int, const);

class word
{
   public:

   word();
   int getCount() { return count; }
   const char *getWord() const { return sWord.c_str(); }

   void setWord( const char* word )
   {
      sWord = word;
      buildPrintString();
   }

   void setCount( int n )
   {
      count = n;
      buildPrintString();
   }

   bool operator== (const word& wrd ) const
   {

      return !sWord.compare( wrd.getWord() );
   }

   bool operator< (word &wrd ) const
   {
      return ( sWord.compare( wrd.getWord() ) < 0 );
   }

   const char *toString() const
   {
      return printStr.c_str();
   }

   private:
   string sWord;
   string printStr;
   int count;

   void buildPrintString()
   {
      char count[10];

      sprintf( count, "%d", this->count );
      printStr = "  ";
      if ( this->count < 9 )
         printStr += " ";
      printStr += count;
      printStr += "  | " + sWord;
   }
};

word::word()
{
   count = 0;
}

int main( int argc, char *argv[] )
{
   if ( argc < 2 )
   {
      cout<<"ERROR - Incorrect number of arguments"<<endl;
      cout<<"Syntax : wordcount filename"<<endl<<endl;
      return 0;
   }

   ifstream file( argv[1] );
   if ( !file.is_open() )
   {
      cout<<"ERROR - Unable to access "<<argv[1]<<endl;
      return 0;
   }

   checkWords(argc, argv);

   return 0;
}

void checkWords( int argc, char *argv[] )
{
   int totalWords = 0, uniqueWords = 0;
   bintree<word> tree;
   ifstream file( argv[1] );

   while ( !file.eof() )
   {
      char buff[256];

      file.getline( buff, 226 );

      char *newword = strtok( buff, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );

      while ( newword )
      {
         // strip any word of double quotes
         string strWord = newword;
         size_t found;

         found = strWord.find_first_of("\"");
         while ( found != string::npos )
         {
            strWord.erase( found, 1 );
            found = strWord.find_first_of( "\"", found+1 );
         }

         if ( strWord.length() < 1 )
         {
            newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
            continue;
         }

         word temp;

         temp.setWord( strWord.c_str() );

         word *find = tree.find( temp );

         // Not in tree, means first occurence of the word
         if ( !find )
         {
            temp.setCount( 1 );
            tree.insert( temp );
            uniqueWords++;
         }
         else
         {
            find->setCount( find->getCount() + 1 );
         }

         totalWords++;
         newword = strtok( NULL, " \t\r\n,;:”~!#%^*()=+[]{}\\|<>?/." );
      }
   }

   printWords(argc, argv, totalWords, uniqueWords, tree);

}

void printWords( int argc, char *argv[], int totalWords, int uniqueWords, const 
bintree<word> tree )
{
//   int totalWords;
//   int uniqueWords;
//   bintree<word> tree;

   cout<<endl<<"filename : "<<argv[1]<<endl<<endl;

   cout<<"COUNT | WORD"<<endl;
   cout<<"------+------"<<endl;
   tree.print();

   cout<<endl;

   cout<<"Number of unique words in "<<argv[1]<<" is "<<uniqueWords<<endl;
   cout<<"Total number of words in "<<argv[1]<<" is  "<<totalWords<<endl;
}
int main(int, char**);

why have you prototyped main? I consider that generally pointless, if not bad practice. If your compiler wants you to, ditch it.
as for your error...

void printWords(int, char**, int, int, const);

I'd hazard a guess that declaring a constant .... nothing is a bad idea :P.
try using this as a prototype

void printWords( int , char**, int , int , const bintree<word>);
// Or better yet....
void printWords( int argc, char** argv, int totalWords, int uniqueWords, const bintree<word> tree );

While there's nothing wrong with defining function prototypes using the variable types adding the variable name makes them much simpler to understand.
also can you please use the code blocks with C++ defined as the language, it makes reading code much easier. rather than typing use (without speech marks obviously.

This article has been dead for over six months. Start a new discussion instead.