lolamontes69

K+R Exercise1_14

Sep 5th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     char c;
  6.     int i, j;
  7.  
  8.     int hist[256];         // to store ascii character count
  9.     for(i=0; i<256; ++i)   // initialize to to 0's
  10.         hist[i]=0;
  11.     while((c = getchar()) != EOF)
  12.         hist[c]++;         // Add 1 to char count in hist[ascii value of c]
  13.     puts("\n   -------- HISTOGRAM --------\n");
  14.     for(i=32; i<126; ++i) {
  15.         printf("%c : ",i);
  16.         for(j=0; j<hist[i]; ++j)
  17.             printf("#");
  18.         printf("\n");
  19.     }
  20.     return(0);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment