11-01-2011, 09:57 AM
The following code will count how many times a character appears in entered input. And create a histogram to detail it. I thought it was some pretty cool code, so I decided to share.
[code=c]#include <stdio.h>
#define EOL '\n'
#define ARYLEN 256 /* Length of Ascii Alphabet.. From 0 */
main(){
int c, i, x;
int length[ARYLEN];
for(x = 0; x < ARYLEN;x++)
length[x] = 0;
while( (c = getchar() ) != EOL){
length[c]++;
if (c == EOL)
break;
}
for(x = 0; x < ARYLEN; x++){
if( length[x] > 0){
printf("%c | ", x);
for(i = 1; i <= length[x]; ++i){
printf("*");
}
printf("\n");
}
}
}[/code]
[code=c]#include <stdio.h>
#define EOL '\n'
#define ARYLEN 256 /* Length of Ascii Alphabet.. From 0 */
main(){
int c, i, x;
int length[ARYLEN];
for(x = 0; x < ARYLEN;x++)
length[x] = 0;
while( (c = getchar() ) != EOL){
length[c]++;
if (c == EOL)
break;
}
for(x = 0; x < ARYLEN; x++){
if( length[x] > 0){
printf("%c | ", x);
for(i = 1; i <= length[x]; ++i){
printf("*");
}
printf("\n");
}
}
}[/code]
;7$=v?%v%#5>v7v8994
The decrypt code is V, I could not make it any simpler!