Can you tell me if I'm starting to have the right idea? I found a way to count all the characters? But I'm sure I have the isalpha function wrong.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <string>
using namespace std;
// Declare constants
// Function Prototypes
int main()
{
// Declare variables below here
string fileName, line;
char ch, x;
int charCount, alphaCount, numCount, spefCount, lineCount;
ifstream infile;
ofstream outfile;
// Initialization Section for real number output. DO NOT MOVE!
cout <<setiosflags(ios::fixed | ios::showpoint);
cout <<setprecision(2);
// Begin your "main processing" below here
charCount=0;
alphaCount=0;
numCount=0;
spefCount=0;
lineCount=0;
cout<<"Please enter the file name >> ";
cin>>fileName;
infile.open(fileName);
cout<<"Please enter a single specific character to search for: "<<endl;
cin>>x;
if (infile.is_open())
{
while( getline (infile, line))
{
charCount += line.length();;
}
}
while (infile.get (ch))
{
if (isalpha(ch))
{
alphaCount++;
}
}
cout<<"Number of characters: "<<charCount<<endl;
cout<<"Number of alpha characters (a-z): "<<alphaCount<<endl;
cout<<"Number of numeric characters (0-9): "<<numCount<<endl;
cout<<"Number of user specified characters: "<<spefCount<<endl;
cout<<"Number of lines: "<<lineCount<<endl;
infile.close( );
return 0;
}
// function definitions below here