howtothings.co.uk
Creating Histogram on Character Occurrences - Printable Version

+- howtothings.co.uk (https://www.howtothings.co.uk)
+-- Forum: Computing (https://www.howtothings.co.uk/forumdisplay.php?fid=4)
+--- Forum: Programming Support, Graphic Design and Tutorials (https://www.howtothings.co.uk/forumdisplay.php?fid=14)
+--- Thread: Creating Histogram on Character Occurrences (/showthread.php?tid=707)

Pages: 1 2 3


Creating Histogram on Character Occurrences - Drumm - 11-01-2011

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]



RE: Creating Histogram on Character Occurrences - latch - 13-01-2011

(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!


RE: Creating Histogram on Character Occurrences - Drumm - 13-01-2011

[Image: screenshotqd.png]


RE: Creating Histogram on Character Occurrences - Pack3t SynAck3r - 14-01-2011

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.


RE: Creating Histogram on Character Occurrences - latch - 14-01-2011

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.


RE: Creating Histogram on Character Occurrences - Pack3t SynAck3r - 14-01-2011

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.


RE: Creating Histogram on Character Occurrences - latch - 14-01-2011

(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.


RE: Creating Histogram on Character Occurrences - Pack3t SynAck3r - 14-01-2011

(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.


RE: Creating Histogram on Character Occurrences - Drumm - 14-01-2011

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.


RE: Creating Histogram on Character Occurrences - Mark - 14-01-2011

SHARN wrote copy, pasted a macbuntu theme. Do it!