Word Count Program

Discussion in 'Computer Science & Culture' started by NightRIDERLMA0, Mar 6, 2003.

Thread Status:
Not open for further replies.
  1. NightRIDERLMA0 Registered Member

    Messages:
    2
    Hi guys... I am having a problem with this program I have to write... I have to write a program that asks for and brings up a text file and then lists all the words in that file and how many times each word has occured. The 2nd part is to list hte words in alphabetical order.... I was able to get hte program to ask for and bring up a txt file but thats all... Can someone please help me ASAP!!! Here is what I have so far:

    #include <iostream.h>
    #include <fstream.h>
    #include <stdlib.h>
    #include "apvector.h"
    #include "apmatrix.h"
    #include "apstring.h"
    #include <conio.h>

    int main()
    {
    apmatrix <apstring> words(0,2, "");
    int i=0, a=0, b=0;
    apstring filename;
    cout <<"Please enter the name of the file you would like to see: ";
    cin>> filename;

    ifstream InFile(filename.c_str(), ios::nocreate);
    if (InFile.fail()){
    cout <<"File could not be opened";
    cout <<endl;
    return(0);
    }else{
    apstring name;
    while(InFile >> name){
    cout <<name; cout<<" ";
    words.resize(i+2, 2);
    name=words[a]=name;
    i++;

    }
    }

    cout<<flush;getch();
    cout<<words[0][0]<<words[1][0] <<flush;
    return(0);

    }
     
Thread Status:
Not open for further replies.

Share This Page