Advertisement
Ne-Biolog

Untitled

May 8th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <malloc/malloc.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5.  
  6. const char Vowels[] = {'a', 'e', 'y', 'u', 'i', 'o'};
  7.  
  8. int max(int x, int y) {
  9. return x > y ? x : y;
  10. }
  11.  
  12. void viewDiagram(char **matrix, int maxHeight) {
  13. FILE *file2 = fopen("output.txt", "w");
  14. for(int i = 0; i < maxHeight; ++i) {
  15. for(int j = 0; j < 6; ++j) {
  16. putc(matrix[i][j], file2);
  17. putc(' ', file2);
  18. }
  19. putc('\n', file2);
  20. }
  21. for(int i = 0; i < 6; ++i) {
  22. putc(Vowels[i], file2);
  23. putc(' ', file2);
  24. }
  25.  
  26. fclose(file2);
  27. }
  28.  
  29. void createDiagram(int *quantity) {
  30. int maxHeight = -1;
  31. for(int i = 0; i < 6; ++i) {
  32. maxHeight = max(maxHeight, quantity[i]);
  33. }
  34. char **matrix = (char**)malloc(sizeof(char*) * maxHeight);
  35. for(int i = 0; i < maxHeight; ++i) {
  36. matrix[i] = (char*)malloc(sizeof(char) * 6);
  37. for(int j = 0; j < 6; ++j) {
  38. matrix[i][j] = ' ';
  39. }
  40. }
  41. for(int i = 0; i < 6; ++i) {
  42. for(int j = maxHeight - 1; j >= maxHeight - quantity[i]; --j) {
  43. matrix[j][i] = '*';
  44. }
  45. }
  46. viewDiagram(matrix, maxHeight);
  47. }
  48.  
  49. void readText(int *quantity) {
  50. freopen("output.txt" , "w" , stdout);
  51. FILE *file1 = fopen("input.txt", "r");
  52.  
  53. char ch = 'Q';
  54. while(ch != EOF) {
  55. ch = fgetc(file1);
  56. if(ch >= 'A' && ch <= 'Z') {
  57. ch -= 32;
  58. }
  59. for(int i = 0; i < 6; ++i) {
  60. if(Vowels[i] == ch) {
  61. quantity[i]++;
  62. }
  63. }
  64. }
  65. fclose(file1);
  66. }
  67.  
  68. int main ()
  69. {
  70. int *quantity = (int*)malloc(sizeof(int) * 6);
  71. for(int i = 0; i < 6; ++i) {
  72. quantity[i] = 0;
  73. }
  74. readText(quantity);
  75. createDiagram(quantity);
  76.  
  77.  
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement