Advertisement
Kalhnyxtakias

Untitled

Jan 14th, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. void print(char * pointer_array[][2], int linelen) {
  2.  
  3. int length = 0, word_count = 1;
  4. const char punctuation[] = ".!?";
  5. *(pointer_array[0][0]) = toupper(*(pointer_array[0][0]));
  6.  
  7. printf("\n%s", pointer_array[0][0]);
  8.  
  9. length += strlen(pointer_array[0][0]);
  10.  
  11. *(pointer_array[0][0]) = tolower(*(pointer_array[0][0]));
  12.  
  13. if (pointer_array[word_count - 1][1] != NULL) {
  14.  
  15. *(pointer_array[0][1]) = toupper( * (pointer_array[0][1]));
  16.  
  17. printf(" (%s)", pointer_array[0][1]);
  18.  
  19. length += strlen(pointer_array[0][1]) + 3;
  20.  
  21. *(pointer_array[0][1]) = tolower( * (pointer_array[0][1]));
  22. }
  23.  
  24. do {
  25. /* If the length of the line is over linelen, print word on line below */
  26. if (length + strlen(pointer_array[word_count][0]) >= linelen) {
  27. /* If there is a punctuation mark before line change, switch to uppercase for first letter */
  28. if (strstr(punctuation, pointer_array[word_count - 1][0]) != NULL) {
  29. *(pointer_array[word_count][0]) = toupper( * (pointer_array[word_count][0]));
  30.  
  31. printf("\n%s", pointer_array[word_count][0]);
  32.  
  33. length = strlen(pointer_array[word_count][0]);
  34.  
  35. *(pointer_array[word_count][0]) = tolower( * (pointer_array[word_count][0]));
  36.  
  37. word_count++;
  38. }
  39. /* Print word in new line */
  40. else {
  41. printf("\n%s", pointer_array[word_count][0]);
  42.  
  43. length = strlen(pointer_array[word_count][0]);
  44.  
  45. word_count++;
  46. }
  47. }
  48. /* If previous word is punctuation mark, switch to uppercase for first letter */
  49. else if (strstr(punctuation, pointer_array[word_count - 1][0]) != NULL) {
  50. *(pointer_array[word_count][0]) = toupper( * (pointer_array[word_count][0]));
  51.  
  52. printf(" %s", pointer_array[word_count][0]);
  53.  
  54. length += strlen(pointer_array[word_count][0]) + 1;
  55.  
  56. *(pointer_array[word_count][0]) = tolower( * (pointer_array[word_count][0]));
  57.  
  58. word_count++;
  59.  
  60. }
  61. /* Print word */
  62. else {
  63. printf(" %s", pointer_array[word_count][0]);
  64.  
  65. length += strlen(pointer_array[word_count][0]) + 1;
  66.  
  67. word_count++;
  68. }
  69.  
  70. /* Print synonyms if they are found*/
  71. if (pointer_array[word_count - 1][1] != NULL) {
  72.  
  73. if (length + strlen(pointer_array[word_count - 1][1]) + 2 >= linelen) {
  74. /* If there is a punctuation mark before line change, switch to uppercase for first letter */
  75.  
  76. if (strstr(punctuation, pointer_array[word_count - 2][0]) != NULL) {
  77. *(pointer_array[word_count - 1][1]) = toupper( * (pointer_array[word_count - 1][1]));
  78.  
  79. printf("\n(%s)", pointer_array[word_count - 1][1]);
  80.  
  81. length = strlen(pointer_array[word_count - 1][1]) + 2;
  82.  
  83. *(pointer_array[word_count - 1][1]) = tolower( * (pointer_array[word_count - 1][1]));
  84. }
  85. /* Print word in new line */
  86. else {
  87.  
  88. printf("\n(%s)", pointer_array[word_count - 1][1]);
  89.  
  90. length = strlen(pointer_array[word_count - 1][1]) + 2;
  91. }
  92. }
  93. /* If previous word is punctuation mark, switch to uppercase for first letter */
  94. else if (strstr(punctuation, pointer_array[word_count - 2][0]) != NULL) {
  95. *(pointer_array[word_count - 1][1]) = toupper( * (pointer_array[word_count - 1][1]));
  96.  
  97. printf(" (%s)", pointer_array[word_count - 1][1]);
  98.  
  99. length += strlen(pointer_array[word_count - 1][1]) + 3;
  100.  
  101. *(pointer_array[word_count - 1][1]) = tolower( * (pointer_array[word_count - 1][1]));
  102.  
  103. }
  104. /* Print word */
  105. else {
  106. printf(" (%s)", pointer_array[word_count - 1][1]);
  107.  
  108. length += strlen(pointer_array[word_count - 1][1]) + 3;
  109.  
  110. }
  111. }
  112. } while (pointer_array[word_count][0] != NULL && word_count < MAX_WORDS);
  113.  
  114. printf("\n");
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement