There really is no hope of making this code even half-way decent without spending the time to rewrite them all properly. Don't want to do any of that
31 lines
725 B
C++
Executable File
31 lines
725 B
C++
Executable File
#include <stdio.h>
|
|
|
|
int main() {
|
|
// Deklaration der Variablen
|
|
int hist[ 26 ] = {};
|
|
int i, k, c, count;
|
|
|
|
// Zeichen bis EOF einlesen (nur a-z werden berücksichtigt)
|
|
// EOF wird im Terminal mit CTRL-D eingegeben!
|
|
while ( ( c = getchar() ) != EOF ) {
|
|
if ( ( c > 96 ) && ( c < 123 ) ) {
|
|
// Zähler für diesen Buchstaben erhöhen
|
|
hist[ c - 97 ]++;
|
|
}
|
|
}
|
|
|
|
// Histogramm ausgeben
|
|
printf( "\n" );
|
|
for ( i = 0; i < 26; i++ ) {
|
|
count = hist[ i ];
|
|
if ( count > 0 ) {
|
|
printf( "%c : ", i + 97 );
|
|
for ( k = 0; k < count; k++ )
|
|
printf( "*" );
|
|
printf( "\n" );
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|