12345678910111213141516171819202122232425262728
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { char string[ 1000 ]; int c = 0; int count[ 26 ] = { 0 }; cout << "Enter a string" << endl; gets( string ); while ( string[ c ] != '\0' ) // Considering characters from 'a' to 'z' only { if ( string[ c ] >= 'a' && string[ c ] <= 'z' ) count[ string[ c ] - 'a' ]++; c++; } for ( int i = 0 ; i < 26 ; i++ ) { if( count[ i ] != 0 ) cout << static_cast< char >( i + 'a' ) << " occurs " << count[ i ] << " times" << endl; } return 0; }
12
char cstring[1000]; cin.getline(cstring,1000);