numbers aren't right when reading text file, have to tally up number of 5 letter words and 6 or more

Posted by user320950 on Stack Overflow See other posts from Stack Overflow or by user320950
Published on 2010-05-05T17:58:33Z Indexed on 2010/05/05 18:08 UTC
Read the original article Hit count: 130

Filed under:
|
|
|

i want to do this: reads the words in the file one at a time. (Use a string to do this) Counts three things: how many single-character words are in the file, how many short (2 to 5 characters) words are in the file, and how many long (6 or more characters) words are in the file. HELP HERE

im not sure on how about reading file into a string. i know i have to something like this but i dont understand the rest. HELP HERE

ifstream infile;
//char mystring[6];
//char mystring[20];

 int main()
    {
        infile.open("file.txt");
            if(infile.fail())
            {
                cout << " Error " << endl;
            }

        int numb_char=0;
        char letter;

                while(!infile.eof())
                {
                    infile.get(letter);
                    cout << letter;
                    numb_char++;
                    break;
                }

    cout << " the number of characters is :" << numb_char << endl;
    infile.close(); 
    return 0;

© Stack Overflow or respective owner

Related posts about practice

Related posts about iostream