Advertisement
fallenangel121

Untitled

Jan 13th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <stdbool.h>
  5. #include <string.h>
  6.  
  7. int text_count = 0;
  8.  
  9. int tab_count = 0;
  10. int space_after_count = 0;
  11. int space_before_count = 0;
  12. int capital_letter_count = 0;
  13. int special_symbol_count = 0;
  14. int multiple_spaces_count = 0;
  15.  
  16. int entire_tab_count = 0;
  17. int entire_space_after_count = 0;
  18. int entire_space_before_count = 0;
  19. int entire_capital_letter_count = 0;
  20. int entire_special_symbol_count = 0;
  21. int entire_multiple_spaces_count = 0;
  22.  
  23. char*AddTab(char*text){ // sled vseki abzac izrechenieto zapochva s 1 tabulaciq navutre
  24.  
  25. char*tmpText = (char*) calloc(strlen(text)*2,sizeof(char)); //*
  26. int i;
  27.  
  28. for (i=0; i < strlen(text); i++){
  29.  
  30. if (i == 0 || text[i] == '\n'){
  31. strncat(tmpText,"\t",1);
  32. entire_tab_count ++;
  33. }
  34. strncat(tmpText,&text[i],1);
  35. }
  36. return tmpText;
  37. }
  38.  
  39. char*AddSpaceAfter(char*text){ //sled vseki prepinatelen znak funkciqta dobavq po 1 shpaciq
  40.  
  41. char*tmpText = (char*) calloc(strlen(text)*2,sizeof(char));
  42. int i;
  43.  
  44. for (i=0;i<strlen(text);i++){
  45.  
  46. if (text[i]=='.' || text[i]=='?' || text[i]==',' || text[i]=='!' || text[i]==';' || text[i]==':'|| text[i]=='"'){
  47.  
  48. strncat(tmpText, &text[i], 1);
  49. strncat(tmpText," ",1);
  50.  
  51. entire_space_after_count++;
  52.  
  53. }else{
  54. strncat(tmpText,&text[i],1);
  55. }
  56. }
  57. return tmpText;
  58. }
  59.  
  60. char* AddSpaceBefore(char* text){ // funkciqta dobavq shpaciq predi lqvata skoba i NE dobavq sled dqsnata
  61. char* tmpText = (char*) calloc(strlen(text) * 2, sizeof(char));
  62. int i;
  63.  
  64. for (i=0; i < strlen(text); i++){
  65. if(text[i] == ' (')
  66. {
  67. strncat(tmpText, " (", 1);
  68. entire_space_before_count++;
  69. continue;
  70. }
  71. strncat(tmpText, &text[i], 1);
  72. }
  73.  
  74. return tmpText;
  75. }
  76.  
  77. char* SentenceToUpper(char*text){ // vsqko izrechenie zapochva s glavna bukva
  78.  
  79. int isNewSentence = 0;
  80.  
  81. char* tmpText = (char*) calloc(strlen(text) * 2, sizeof(char));
  82. int i;
  83.  
  84. for (i=0; i < strlen(text); i++){
  85.  
  86. if (text[i]=='.'|| text[i]=='!' || text[i]=='?'){
  87. strncat(tmpText, &text[i], 1);
  88. strncat(tmpText, " ", 1);
  89. isNewSentence = 1;
  90. continue;
  91. }
  92.  
  93. if (isNewSentence == 1){
  94.  
  95. char temp = toupper(text[i]);
  96.  
  97. strncat(tmpText, &temp, 1);
  98. isNewSentence = 0;
  99.  
  100. entire_capital_letter_count++;
  101. }
  102. else{
  103. strncat(tmpText, &text[i], 1);
  104. }
  105. }
  106. return tmpText;
  107. }
  108.  
  109.  
  110. char* RemoveSpecialChars(char* text){ //vseki simvol sys stoynost po-golqma ot 127 biva premahvan
  111. char* tmpText = (char*) calloc(strlen(text) * 2, sizeof(char));
  112.  
  113. for (int i = 0; i < strlen(text); i++) {
  114.  
  115. if ((text[i] - '0') > 127){
  116. entire_special_symbol_count++;
  117. strncat(tmpText, &text[i], 1);
  118. }else{
  119. strncat(tmpText, &text[i], 1);
  120. }
  121. }
  122.  
  123. return tmpText;
  124. }
  125.  
  126. char* RemoveMultipleSpaces(char* text){ //prazni razstoqniq po-golemi ot 1 shpaciq bivat namaleni do 1
  127. char* tmpText = (char*) calloc(strlen(text) * 2, sizeof(char));
  128. int i;
  129.  
  130. for (i = 0; i < strlen(text)-1; i++){
  131.  
  132. if(text[i] == ' ' && text[i+1] == ' ')
  133. {
  134. entire_multiple_spaces_count++;
  135.  
  136. }else{
  137. strncat(tmpText, &text[i], 1);
  138. }
  139. }
  140. return tmpText;
  141. }
  142.  
  143.  
  144. int main()
  145. {
  146. while (true){
  147. char text [2000];
  148.  
  149. printf("Enter text:\n");
  150. fflush(stdin);
  151. fgets(text, 1000, stdin);
  152.  
  153. char* editedText = (char*) malloc(sizeof(char)*2000);
  154. text_count++;
  155.  
  156. strcpy(editedText, SentenceToUpper(text));
  157. strcpy(editedText, AddSpaceAfter(editedText));
  158. strcpy(editedText, AddTab(editedText));
  159. strcpy(editedText, AddSpaceBefore(editedText));
  160. strcpy(editedText, RemoveMultipleSpaces(editedText));
  161. strcpy(editedText, RemoveSpecialChars(editedText));
  162.  
  163.  
  164. float averageTabs = entire_tab_count/text_count;
  165. float averageSpacesBefore = entire_space_before_count/text_count;
  166. float averageSpacesAfter = entire_space_after_count/text_count;
  167. float averageCapitalLetters = entire_capital_letter_count/text_count;
  168. float averageSpecialSymbols = entire_special_symbol_count/text_count;
  169. float averageMultipleSpaces = entire_multiple_spaces_count/text_count;
  170.  
  171. printf("\nFormatted text:\n%s\n", editedText);
  172. printf("\nAdded tabs: %d (Average: %.2f)\n", entire_tab_count, averageTabs);
  173. printf("Added spaces before char: %d (Average: %.2f)\n", entire_space_before_count, averageSpacesBefore);
  174. printf("Added spaces after char: %d (Average: %.2f)\n", entire_space_after_count, averageSpacesAfter);
  175. printf("Changed letters to upper case: %d (Average: %.2f)\n", entire_capital_letter_count, averageCapitalLetters);
  176. printf("Removed special symbols: %d (Average: %.2f)\n", entire_special_symbol_count, averageSpecialSymbols);
  177. printf("Removed multiple spaces: %d (Average: %.2f)\n", entire_multiple_spaces_count, averageMultipleSpaces);
  178.  
  179. }
  180. return 0;
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement