// Comment below is for html previewing only
//
#include
#include
#include // for ifstream
using namespace std;
#include "prompt.h"
#include "utils.h"
// Name:
// Date:
// Course: CPS 6, Section ?
// Purpose:
const string PATH_ECLIPSE_LOCAL = "C:\\Program Files\\eclipse\\workspace\\countw2\\";
const string PATH_ECLIPSE_REMOTE = "P:\\public\\cps6group\\countw2\\";
const string PATH_UNIX = "";
const string PATH = PATH_ECLIPSE_LOCAL;
int CountWords (const string& filename)
// pre: filename exists
// post: returns number of words in filename
{
int numWords = 0; // initially no words
ifstream input;
string word;
input.open(filename.c_str()); // bind input to named file
while (input >> word) // read succeeded
{
numWords++;
}
input.close();
return numWords;
}
int main (int argc, char * argv[])
{
string name = PromptString("enter name of file: ");
cout << "number of words read = " << CountWords(PATH + name) << endl;
string name2 = PromptString("enter name of file: ");
cout << "number of words read = " << CountWords(PATH + name2) << endl;
WaitForReturn();
return 0;
}
//