Find the answer to your Linux question:
Results 1 to 2 of 2
So I am trying to create a function that is in a seperate file that will count words from a text file. I have the streams set up and it ...
  1. #1
    Just Joined!
    Join Date
    Feb 2009
    Posts
    1

    Help with C++ h/w on Counting Words

    So I am trying to create a function that is in a seperate file that will count words from a text file. I have the streams set up and it is a pass by referance function so some variables are declared in the main program. I have been working on this for a couple days now and just can't seem to get it to work . Below is the code for the function so if anyone has any suggestions please let me know thank you!!

    #include <fstream>
    #include <iostream>
    using namespace std;

    char WordCount(int& Word)
    {
    bool WordCheck = false;
    char Tester;
    ifstream in;
    in.open("/export/home/wyatt/public_html/!Data/data244.txt");

    in.get(Tester);

    while(!in.eof())
    {
    if((Tester != ' ')||(Tester != '\t')||(Tester != '\n')||(Tester != 'endl'))
    WordCheck = true;

    else
    WordCheck = false;

    if(WordCheck == false)
    Word ++;

    in.get(Tester);
    }

    cout << "The total number of words in this text document are: " << Word;

    return 0;
    }

  2. #2
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    I'm sorry, we can't offer help on homework questions, as per the forum rules:

    http://www.linuxforums.org/forum/lin...ums-rules.html
    Registered Linux user #270181
    TechieMoe's Tech Rants

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...