Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   about using input file (File I/O stream) (http://www.go4expert.com/forums/using-input-file-file-i-o-stream-t2614/)

01wlau 19Jan2007 14:31

about using input file (File I/O stream)
 
I got a problem about File I/O stream. I have created a text file which is called input.txt which contains 80 characters in each line. The follwoing codes I did typed, but, I don't know how to use the input file to calculate the numbers of upper cases and the numbers of lines. Please help me!
Code:

#include <iostream>
#include <string>
using namespace std;
#include <fstream>
int main()
{
        ifstream fin1 ("input.txt");
        if (!fin1)
        {
                cout << "Cannot open infile: input.txt\n";
        }
        else
        {
                cout << "Infile: input.txt opened.\n";
                cout << "Number of spaces: ";
                char ch[1000];
                fin1.read(ch,1000);
                int numchar = strlen(ch);
                int count1 = 0;
                for (int i=0;i<numchar;i++)
                {
                                if (ch[i] == ' ')
                                        count1++;
                }
                cout << count1;
                cout << endl;
                cout << "Number of upper cases: ";
                int sum1 = 0;
                for (int i=0; i<numchar;i++)
                {
                        if (isupper(*ch))
                                sum1++;
                }
                cout << sum1;
                cout << endl;
                cout << "Number of lines: ";
                cout << endl;
        }
        return 0;
}

Thanks a lot!!!


All times are GMT +5.5. The time now is 13:22.