howtothings.co.uk

Full Version: Creating Histogram on Character Occurrences
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
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]
(11-01-2011, 09:57 AM)Drumm Wrote: [ -> ]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]

Should have included a screen shot!
[Image: screenshotqd.png]
Dude you need to change the default settings on your terminal, like turn off that shit transparency and change the color to something less purplish. The code is good though, keep it up.
The transparency isn't bothering me- I just wanted to SEE what he was doing. Thanks Drumm. I like writing things like this for my own amusement, too. If you write a sentence, the space always has the longest set of asterisks on the top there.
Whether it is bothering you has no relevance. I am the one leading DM down the path of light, and if I ever see ask him for a screenshot I would prefer something less fruity in the color coordination. Thanks anyway latch.
(14-01-2011, 06:07 AM)Pack3t SynAck3r Wrote: [ -> ]Whether it is bothering you has no relevance. I am the one leading DM down the path of light, and if I ever see ask him for a screenshot I would prefer something less fruity in the color coordination. Thanks anyway latch.

You didn't ask for a screenshot! I did and I didn't care if it was fruity, but if that gets in your way of mentoring, I'll step aside.
(14-01-2011, 06:12 AM)latch Wrote: [ -> ]
(14-01-2011, 06:07 AM)Pack3t SynAck3r Wrote: [ -> ]Whether it is bothering you has no relevance. I am the one leading DM down the path of light, and if I ever see ask him for a screenshot I would prefer something less fruity in the color coordination. Thanks anyway latch.

You didn't ask for a screenshot! I did and I didn't care if it was fruity, but if that gets in your way of mentoring, I'll step aside.

This is a matter for future reference. Drumm and I communicate off the beaten path on occasion, and if I request a screenshot (which is quite possible) I would like a more optically pleasing contrast. Nothing can stop me from mentoring MWA HA HA. You and your beta harmonics. You know very well the alpha route is more efficient.
The Space comes first because it's earlier in the ascii alphabet. If you would not like it too show, spaces change this line
Code:
if( length[x] > 0){
to
Code:
if( length[x] > 0 && x < 33){

I don't tend to mess with defaults when It comes to looks. A lot of things can be left the same. I'll set it too Green on Black, Just for you. And find a nice theme like I used to have. I haven't been in Ubuntu long enough too fix it anyway.
SHARN wrote copy, pasted a macbuntu theme. Do it!
Pages: 1 2 3