Hello,

First off, I'm using borland c++ builder 4 (I know, my school's outdated)

I need to count the number of words in a text file (which contains the US Constitution, and it's amendments). I need to output the total number of: words in the entire text file, words in preamble, words in each article (out put separately), and words in each Amendment (output separately). I also need to count the number of occurrences of a word that the user defines and output that (the first part is more important at this time).

I don't have much done, but what I do have is code to count it once in it's entirety and output that.

Code:
#pragma hdrstop
#include <condefs.h>
#include <conio.h>
#include <iostream.h>

//---------------------------------------------------------------------------
#pragma argsused


#define NULL 0
FILE *fpt;
void main()
{

char name[20],c;
int newv = 0;
clrscr();
printf("Enter the name of file to be checked:- ");
gets(name);
fpt=fopen(name,"r");
if (fpt==NULL)
{
printf("ERROR - can/'t open file %s",name);
getch();
exit(0);
}
else
{
while ((c=getc(fpt))!=EOF)
{
switch(1)
{
case 1:
if (c==' ')
{
point: // do
// new = new+1-1;
while((c=getc(fpt))==' ');

if (c!=' ')
newv = newv +1;
if(c==' ')newv--;
}


// case 3:
if(c==' '){
goto point;}

}
}
}
cout << "Document: " << name << " contains: "<< newv << " words";
getch();
}
I will be awaiting your assistance, thanks.

rockage