Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- int main()
- {
- string word;
- ifstream inData;
- string fileName;
- int counter=0;
- char prevChar;
- char currChar;
- int count=0;
- int working=0;
- while(fileName!="exit")
- {
- cout<<"Please enter a file name ";
- //do { cin >> fileName; } while (fileName != "exit");
- cin>>fileName;
- if(fileName=="exit")
- break;
- inData.open(fileName.c_str());
- count=0;
- //inData.get(prevChar);
- //inData.get(currChar);
- while(inData)
- {
- if (currChar == ' ' &&
- prevChar != ' '||prevChar=='.')
- count++;
- prevChar = currChar;
- inData.get(currChar);
- cout<<currChar;
- }
- /*while(inData)
- {
- inData>>word;
- counter++;
- cout<<word;
- }*/
- cout<<"The number of words in the file is "<<count-1<<endl;
- }
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment