Advertisement
Guest User

Untitled

a guest
Apr 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "stdio.h"
  3. #include "string.h"
  4. FILE *x; FILE *y;
  5. int Vi[10][100];
  6. int del[1000];
  7. char text[1000000]; char str[10][100]; char text1[1000000];
  8. int OR(int m, int b)
  9. {
  10. int R = 0;
  11. for (int i = 0; i < b; i++)
  12. {
  13. if (m == del[i])
  14. {
  15. R++;
  16. break;
  17. }
  18. }
  19. return R;
  20. }
  21.  
  22. int BM(char str[10][100], int t)
  23. {
  24. int M, N, u;
  25. M = strlen(str[t]);
  26. N = strlen(text);
  27. Vi[t][0] = M;
  28. u = 1;
  29. int i = -1;
  30. D: int j = 0;
  31. while (j<M && (++i) <= N - M)
  32. {
  33. j = 0;
  34. while (j<M && text[i + j] == str[t][j])
  35. {
  36. j++;
  37. }
  38. }
  39. if ((i <= N - M) && ((text[i + M] == ' ') || (text[i + M] == '\0') || (text[i + M] == '\n') || (text[i + M] == ')') || (text[i + M] == ',') || (text[i + M] == '.') || (text[i + M] == '?') || (text[i + M] == '!') || (text[i + M] == ';') || (text[i + M] == ':') || (text[i + M] == ']') || (text[i + M] == '\"')) && ((text[i - 1] == ' ') || (text[i - 1] == NULL)))
  40. {
  41. Vi[t][u] = i;
  42. u++;
  43. }
  44. i = i + M;
  45. if (i <= N - M)
  46. {
  47. goto D;
  48. }
  49. return(*(*(Vi + t) + u));
  50. }
  51.  
  52.  
  53. int main()
  54. {
  55. int beg, end, b, k, t;
  56. x = fopen("x.txt", "r");
  57. if (x == NULL)
  58. {
  59. printf("Error1\n");
  60. }
  61. else
  62. {
  63. printf("The file is opened for reading.\n");
  64. }
  65. y = fopen("y.txt", "w");
  66. if (y == NULL)
  67. {
  68. printf("Error2\n");
  69. }
  70. else
  71. {
  72. printf("The file is opened for writing.\n");
  73. }
  74. fseek(x, 0L, SEEK_END);
  75. int N = ftell(x);
  76. fseek(x, 0L, SEEK_SET);
  77. for (int h = 0; h<N; h++)
  78. {
  79. text[h] = fgetc(x);
  80. }
  81. printf("The source text from a file:\r\n");
  82. printf("%s\r\n", text);
  83. printf("\r\n");
  84. while (1)
  85. {
  86. printf("Enter the number of words or phrases you want to delete:");
  87. scanf_s("%d\r\n", &k);
  88. J:
  89. if (k > 10 || k <= 0)
  90. {
  91. printf("Please the number of words or phrases you want to delete again:");
  92. scanf_s("%d\r\n", &k);
  93. goto J;
  94. }
  95. if (k <= 10 && k>0)
  96. {
  97. break;
  98. }
  99. }
  100. for (int y = 0; y<k; y++)
  101. {
  102. gets_s(str[y]);
  103. }
  104. printf("\r\n");
  105. for (int i = 0; i<k; i++)
  106. {
  107. for (int j = 0; j<100; j++)
  108. {
  109. Vi[i][j] = -6;
  110. }
  111. }
  112. for (t = 0; t<k; t++)
  113. {
  114. BM(str, t);
  115. }
  116. b = 0;
  117. for (int i = 0; i < k; i++)
  118. {
  119. for (int j = 1; j < 100; j++)
  120. {
  121. if (Vi[i][j] >= 0)
  122. {
  123. beg = Vi[i][j];
  124. end = Vi[i][j] + Vi[i][0];
  125. if (text[end] == ' ')
  126. {
  127. end++;
  128. }
  129. else if ((text[end] != ' ') && (text[beg - 1] == NULL || text[beg - 2] == '.' || text[beg - 2] == '?' || text[beg - 2] == '!'))
  130. {
  131. end = end + 2;
  132. }
  133. else if (text[end] != ' ' && text[beg - 1] == ' ')
  134. {
  135. beg--;
  136. }
  137. for (int y = beg; y < end; y++)
  138. {
  139. del[b] = y;
  140. b++;
  141. }
  142. }
  143. }
  144. }
  145. int v = 0;
  146. for (int m = 0; m < N; m++)
  147. {
  148. int R;
  149. R = OR(m, b);
  150. if (R == 0)
  151. {
  152. text1[v] = text[m];
  153. v++;
  154. }
  155. }
  156. printf("New text:\r\n");
  157. printf("%s\r\n", text1);
  158. printf("\r\n");
  159. for (int p = 0; p<N; p++)
  160. {
  161. fputc(text1[p], y);
  162. }
  163. fclose(x);
  164. fclose(y);
  165. int n = _fcloseall();
  166. printf("Numbers of files closed by _fcloseall: %u\n", n);
  167. return 0;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement