ey all, i was wondering if you can all help me with this program. what it does it counts the number of letters in a file, in this case info.dat, and also counts the number of characters used, regardless of whether it is numeric, alpha, spaces, etc.
purpose of this is so that i can subtract the 2 and get the number of words. there might be other ways of doing it -- but this is how i approached the problem, and it suffices for now. but the problem is that i can not get a proper amount of letters to display. when using the loop inside main, i do get the right amount of letters. so i'm assuming i'm not bringing in the fstream variable in correctly into the function. if you guys can help, i'd appreciate it.
Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cctype>
using namespace std;
int intfuncCharacters (ifstream ifsFileIn_par);
int intfuncLetters (ifstream ifsFileIn_par);
void main()
{
ifstream ifsFileIn;
int intLetters = 0, intCharacters= 0;
char chrCharacter;
intCharacters = intfuncCharacters(ifsFileIn);
intLetters = intfuncLetters(ifsFileIn);
cout << intCharacters;
}
int intfuncLetters (ifstream ifsFileIn_par)
{
ifsFileIn_par.open("info.dat");
char chrCharacter;
int intDummyLetters;
while(ifsFileIn_par.get(chrCharacter))
{
if (isalpha(chrCharacter))
intDummyLetters ++;
}
ifsFileIn_par.close ();
return (intDummyLetters);
}
int intfuncCharacters (ifstream ifsFileIn_par)
{
char chrCharacter;
int intDummyLetters;
while(ifsFileIn_par.get(chrCharacter))
{
intDummyLetters ++;
}
return (intDummyLetters);
}