• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Histogram on Character Occurrences
#1
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]
[Image: nomnomnom.jpg]
;7$=v?%v%#5>v7v8994
The decrypt code is V, I could not make it any simpler!
  Reply
#2
(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!
Having long hair is great until you have to pull a footlong out of the dog's butt. flatank.blogspot.com
I. AM. LATCH.
  Reply
#3
[Image: screenshotqd.png]
[Image: nomnomnom.jpg]
;7$=v?%v%#5>v7v8994
The decrypt code is V, I could not make it any simpler!
  Reply
#4
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.
[Image: icpn5k.jpg]
Trolls are the last thing you need to be concerned with.

VCD Wrote:// Forever more, count and reply, bitch.
  Reply
#5
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.
Having long hair is great until you have to pull a footlong out of the dog's butt. flatank.blogspot.com
I. AM. LATCH.
  Reply
#6
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.
[Image: icpn5k.jpg]
Trolls are the last thing you need to be concerned with.

VCD Wrote:// Forever more, count and reply, bitch.
  Reply
#7
(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.
Having long hair is great until you have to pull a footlong out of the dog's butt. flatank.blogspot.com
I. AM. LATCH.
  Reply
#8
(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.
[Image: icpn5k.jpg]
Trolls are the last thing you need to be concerned with.

VCD Wrote:// Forever more, count and reply, bitch.
  Reply
#9
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.
[Image: nomnomnom.jpg]
;7$=v?%v%#5>v7v8994
The decrypt code is V, I could not make it any simpler!
  Reply
#10
SHARN wrote copy, pasted a macbuntu theme. Do it!
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a custom mcompute theme Mark 10 22,551 18-10-2010, 10:57 PM
Last Post: Mark

Forum Jump: