Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <fstream>
  4. #include <string>
  5. #include <iomanip>
  6. #include <vector>
  7. #include <string>
  8.  
  9. using namespace std;
  10. //size_t wc(istream &read_stream)
  11. //{
  12. // string word;
  13. // size_t cnt = 0;
  14. //
  15. // while( read_stream >> word )
  16. // {
  17. // cnt++;
  18. // }
  19. //
  20. // return cnt;
  21. //}
  22.  
  23. //// program zlicza libcze a w ca³ym tekscie i daje do characters[0]
  24. void count_characters(istream &read_stream, size_t characters[26])
  25. {
  26. size_t u = 0;
  27. char y;
  28.  
  29. while(read_stream.get(y))
  30. {
  31. y = tolower(y);
  32. // range
  33. if(y >= 'a' && y<='z')
  34. {
  35. characters[y-'a']++;
  36. }
  37. }
  38. for (int i = 0; i<26;i++)
  39. {cout<<characters[i]<<endl;}
  40.  
  41. }
  42. //// for a=2087 i print *** to MAX
  43. //void print_histogram (std::size_t &characters[26], const int MAX)
  44. //{
  45. //
  46. //}
  47.  
  48. int main()
  49. {
  50. size_t characters[26];
  51. ifstream read_stream("texts/hamlet.txt");
  52.  
  53. // if (!read_stream.is_open())
  54. // {
  55. // std::cout << "File was not opened!"<<std::endl;
  56. // }
  57.  
  58. // std::cout << wc(read_stream)<< std::endl;
  59.  
  60.  
  61. count_characters(read_stream,characters);
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement