fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <string>
  4.  
  5. unsigned repeatingCharCount(char const* s)
  6. {
  7. std::string unique ;
  8.  
  9. const unsigned length = std::strlen(s) ;
  10.  
  11. for ( unsigned i = 0; i<length; ++i )
  12. {
  13. if ( std::string::npos == unique.find(s[i]) )
  14. unique += s[i] ;
  15. }
  16.  
  17. std::cout << unique << '\n' ; // ** change here **
  18.  
  19. return length - unique.length() ;
  20. }
  21.  
  22. int main()
  23. {
  24. char buffer[1000] ; // ick.
  25.  
  26. std::cout << "Enter a string\n" ;
  27. std::cin.getline(buffer, 1000) ; // ** change here **
  28. // std::cin >> buffer ;
  29.  
  30. std::cout << '"' << buffer << "\" has "
  31. << repeatingCharCount(buffer) << " repeats.\n" ;
  32. }
Success #stdin #stdout 0s 3432KB
stdin
Only three more lessons to go after this one!
stdout
Enter a string
Only thremosgafi!
"Only three more lessons to go after this one!" has 28 repeats.