Guest User

Untitled

a guest
Jan 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string word;
  9. ifstream inData;
  10. string fileName;
  11. int counter=0;
  12. char prevChar;
  13. char currChar;
  14. int count=0;
  15. int working=0;
  16.  
  17. while(fileName!="exit")
  18. {
  19. cout<<"Please enter a file name ";
  20. //do { cin >> fileName; } while (fileName != "exit");
  21. cin>>fileName;
  22. if(fileName=="exit")
  23. break;
  24.  
  25. inData.open(fileName.c_str());
  26. count=0;
  27. //inData.get(prevChar);
  28. //inData.get(currChar);
  29. while(inData)
  30. {
  31. if (currChar == ' ' &&
  32. prevChar != ' '||prevChar=='.')
  33. count++;
  34. prevChar = currChar;
  35. inData.get(currChar);
  36. cout<<currChar;
  37. }
  38.  
  39. /*while(inData)
  40. {
  41. inData>>word;
  42. counter++;
  43. cout<<word;
  44. }*/
  45. cout<<"The number of words in the file is "<<count-1<<endl;
  46. }
  47. system("PAUSE");
  48. return 0;
  49. }
Add Comment
Please, Sign In to add comment