fork download
  1. #include <iostream>
  2. #include<iomanip>
  3. #include <string>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7. //Function to remove garbage off word
  8. void onlyAlpha(string& str1)
  9. {
  10. string newStr1 ="";
  11. newStr1.reserve(str1.size());
  12.  
  13. for(string::size_type i = 0; i < str1.size(); i++)
  14. {
  15. if ( isalpha( str1[i] ) )
  16. newStr1.push_back( str1[i] );
  17. }
  18. str1 = newStr1;
  19. }
  20.  
  21.  
  22. //A function to determine frequency of letters
  23. void fillFrequency(string str1, int freqcount[], const int alphabet)
  24. {
  25. int position = 0;
  26.  
  27. for(string::size_type i = 0; i < str1.size(); i++)
  28. {
  29. str1[i] = toupper(str1[i]);
  30.  
  31. ++(freqcount[str1[i] - 'A']);
  32.  
  33.  
  34. }
  35.  
  36.  
  37.  
  38. }
  39.  
  40.  
  41. //Function to fill new array with new words.
  42. void funfun(string str1[], const int isize, int& countWord)
  43. {
  44.  
  45. for(int i = 0; i < isize; i++)
  46. {
  47. onlyAlpha(str1[i]);
  48. countWord++;
  49. }
  50. }
  51.  
  52.  
  53. int main()
  54. {
  55. const int isize = 3;
  56. string str1[] = {"!!HELLO","WHAT###", "%%left"};
  57. string test = "haha";
  58. const int size = 100;
  59. string wordsminus[size];
  60. int wordCount = 0;
  61. const int alphabet = 26;
  62. int freqcount[alphabet];
  63. memset(freqcount, 0, 26*sizeof(int));
  64. onlyAlpha(test);
  65. cout << test << endl;
  66. fillFrequency(test, freqcount, alphabet);
  67.  
  68. for(int j = 0; j < alphabet; j++)
  69. {
  70. cout << freqcount[j] << "\t";
  71. }
  72. return 0;
  73.  
  74. }
Success #stdin #stdout 0.01s 2860KB
stdin
Standard input is empty
stdout
haha
2	0	0	0	0	0	0	2	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0