Thread: Please Help

  1. #1
    Unregistered
    Guest

    Please Help

    could someone please help me with a program? This is for a class i am taking in college and yes i did read all of the guidelines about not asking for help with homework and I normally wouldn't ask for help but i am totally stumped. This is driving me up the wall. I have to write a program that prints out the number of words in a text file. You know just do a Word Count. I am suppose to do it 2 different ways 1. Use a string object into which you input each word as a string. 2. Assume the string class (or include file) does not exist, and input the data one character at a time.
    This is what i have done so far:
    #include <iostream>
    #include <string>
    #include <fstream>

    using namespace std;

    void main ()
    {
    ifstream infile;
    string word1;

    infile.open("textfile.txt");
    if (' ' == character)
    wordCount++

    }

    Here is part of a program that i did to count commas in something
    cin.get (inChar)
    while (cin)
    {
    cin.get(inChar)
    while (inCHar != '\n')
    if (inChar == ',')
    commaCount ++;
    I know that i am supposed to do something similar for the word count thing. I dont know. ANy help would be greatly appreciated. And yes i know i am a complete idiot with this stuff and that this should be really easy.

  2. #2
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    smack the teacher, it works
    I was gunna give you how to count all the characters, but that isn't how your teacher wanted it. Plus it was in C style. Why do I give you this information? because this person is cool -->

Popular pages Recent additions subscribe to a feed