: #include <iostream>
: #include <fstream>
: #include <string>
: #include <cstdlib>
:
:
: using namespace std;
:
: void LetterCount (void);
:
:
: int letter;
: char letter, inputChar;
:
: string inputWord;
: ifstream inFile;
: ofstream outFile;
:
: int main ()
: {
:
: inFile.open ("input.txt");
:
: outFile.open ("output.txt");
:
: letter=0;
:
:
: while (inFile>>inputLetter)
:
: LetterCount ();
:
: while (inFile>>letter)
:
:
: cout<<"Letter Count is "<<letter<<"."<<endl;
:
: return 0;
: }
:
: void LetterCount (void)
: {
: letter++;
: }
If I understand you correctly you're looking to do something like this?
Say the file contains 3 words such as: One two three
And you want to count them and output that to a file so the output would be to the file: 3 3 5
#include <fstream>
int main(int argc, char** argv)
{
int count = 0;
char ch;
ifstream infile;
ofstream outfile;
infile.open("input.txt");
outfile.open("output.txt");
while(!infile.eof())
{
infile >> c;
while(c != ' ') // loop till space is found
{
count++;
infile >> c; // get next char
}
outfile << count + " "; // write space to keep counts space for reading
count = 0; // reset counter
}
infile.close();
outfile.close();
return 0; // standard C/C++ exit code of success
}
That code has not been compiled nor tested but should be similar to what you're looking for in respects to how to actually count the number of chars per character and then output that result.
We'll be an army of theives
Of self-freed slaves
Of mild-mannered maids
We'll fight with whispers and blades
So get ready, a new day is dawning
- The New Wild West -- Jewel