Advertisement
Guest User

Untitled

a guest
Nov 10th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. #define IN        1
  4. #define OUT       0
  5. #define MAXLENGTH 11
  6.  
  7. int main()
  8. {
  9.   int i = 0;
  10.   int j =0;  /* i and j are simply index counters */  
  11.   int c = 0;
  12.   int nchar = 0;  /* number of characters in a word */
  13.   int inspace = IN; /* a flag to know whether we are inside of outside the word */
  14.   int wordlen[MAXLENGTH]; /* counts how many words of a particular length we have seen */
  15.  
  16.   for(i = 0; i < MAXLENGTH; ++i)
  17.     wordlen[i] = 0;
  18.  
  19.   while((c = getchar()) != EOF)
  20.     {
  21.       if(c == ' ' || c == '\t' || c == '\n')
  22.     {
  23.       if (inspace == OUT)
  24.         {
  25.           if(nchar < MAXLENGTH)
  26.         ++wordlen[nchar];
  27.         }
  28.      
  29.       inspace = IN;
  30.       nchar = 0;
  31.     }
  32.       else
  33.     {
  34.       ++nchar;
  35.       if(c == '"' || c == '\'')
  36.         --nchar;
  37.       inspace = OUT;
  38.     }
  39.     }
  40.  
  41.  
  42.   /* printing the Horizontal-Histogram */
  43.   for(i = 1; i < MAXLENGTH; ++i)
  44.     {
  45.       printf("%2d| ", i);
  46.       for(j = 0; j < wordlen[i]; ++j)
  47.     putchar('*');
  48.  
  49.       putchar('\n');
  50.     }
  51.  
  52.  
  53.   return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement