Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5.  
  6. #define ASCENDING 1
  7. #define DESCENDING -1
  8. #define INITIAL_SIZE 10
  9.  
  10. void print(int[]);
  11. int main(int argc, char * argv[])
  12. {
  13. char *w;
  14. char c;
  15. char **words;
  16. char buf[64];
  17. int i;
  18. int numWords = 0;
  19. int count = 0;
  20. words = (char **) calloc(INITIAL_SIZE, sizeof(char *));
  21. int length[15];
  22. for(i = 0; i < 15; i++)
  23. {
  24. length[i] = 0;
  25. }
  26. FILE * f;
  27. f = stdin;
  28. c = getc(f);
  29. w = buf;
  30. while(c != EOF)
  31. {
  32. if(isalpha(c))
  33. {
  34. *w++ = c;
  35. count++;
  36. }else{
  37. if (buf == w)
  38. {
  39. c = getc(f);
  40. continue;
  41. }
  42. *w++ = 0;
  43. w = buf;
  44. numWords++;
  45. length[count]++;
  46. count = 0;
  47. }
  48. c = getc(f);
  49. }
  50. print(length);
  51. }
  52.  
  53. void print(int a[])
  54. {
  55. int i, j;
  56. for(i = 0; i < 15; i++)
  57. {
  58. printf("%d. ", i);
  59. for(j = 0; j < a[i]; j++)
  60. {
  61. printf("*");
  62. }
  63. printf("\n");
  64.  
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement