Advertisement
Guest User

unrecognized characters in console

a guest
Jan 25th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. /* Write a program to print a histogram of the frequencies of different characters in its input. */
  2.  
  3. #include <stdio.h>
  4. #define ASCII_LIMIT 128
  5.  
  6. main() {
  7.     int input;
  8.     int characters[ASCII_LIMIT] = { 0 };
  9.     while ((input = getchar()) != EOF) {
  10.         ++characters[input];
  11.     }
  12.  
  13.     for (int h = 0; h < ASCII_LIMIT; h++) {
  14.         printf("%c: ", h);
  15.         for (int g = 0; g < characters[h]; g++) {
  16.             printf("x ");
  17.         }
  18.         putchar('\n');
  19.     }
  20. }
  21.  
  22.  
  23.  
  24. ######### OUTPUT #########
  25. bacon is delicious
  26. ^Z
  27.  :
  28. :
  29. :
  30. :
  31. :
  32. :
  33. :
  34. :
  35. :
  36.         :
  37.  
  38. : x
  39. :
  40. :
  41. :
  42. :
  43. :
  44. :
  45. :
  46. :
  47. :
  48. :
  49. :
  50. :
  51. :
  52. :
  53. :
  54. :
  55.  
  56. :
  57. :
  58. :
  59. :
  60.  : x x
  61. !:
  62. ":
  63. #:
  64. $:
  65. %:
  66. &:
  67. ':
  68. (:
  69. ):
  70. *:
  71. +:
  72. ,:
  73. -:
  74. .:
  75. /:
  76. 0:
  77. 1:
  78. 2:
  79. 3:
  80. 4:
  81. 5:
  82. 6:
  83. 7:
  84. 8:
  85. 9:
  86. ::
  87. ;:
  88. <:
  89. =:
  90. >:
  91. ?:
  92. @:
  93. A:
  94. B:
  95. C:
  96. D:
  97. E:
  98. F:
  99. G:
  100. H:
  101. I:
  102. J:
  103. K:
  104. L:
  105. M:
  106. N:
  107. O:
  108. P:
  109. Q:
  110. R:
  111. S:
  112. T:
  113. U:
  114. V:
  115. W:
  116. X:
  117. Y:
  118. Z:
  119. [:
  120. \:
  121. ]:
  122. ^:
  123. _:
  124. `:
  125. a: x
  126. b: x
  127. c: x x
  128. d: x
  129. e: x
  130. f:
  131. g:
  132. h:
  133. i: x x x
  134. j:
  135. k:
  136. l: x
  137. m:
  138. n: x
  139. o: x x
  140. p:
  141. q:
  142. r:
  143. s: x x
  144. t:
  145. u: x
  146. v:
  147. w:
  148. x:
  149. y:
  150. z:
  151. {:
  152. |:
  153. }:
  154. ~:
  155. :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement