Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "stdio.h"
- #include "string.h"
- FILE *x; FILE *y;
- int Vi[10][100];
- int del[1000];
- char text[1000000]; char str[10][100]; char text1[1000000];
- int OR(int m, int b)
- {
- int R = 0;
- for (int i = 0; i < b; i++)
- {
- if (m == del[i])
- {
- R++;
- break;
- }
- }
- return R;
- }
- int BM(char str[10][100], int t)
- {
- int M, N, u;
- M = strlen(str[t]);
- N = strlen(text);
- Vi[t][0] = M;
- u = 1;
- int i = -1;
- D: int j = 0;
- while (j<M && (++i) <= N - M)
- {
- j = 0;
- while (j<M && text[i + j] == str[t][j])
- {
- j++;
- }
- }
- 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)))
- {
- Vi[t][u] = i;
- u++;
- }
- i = i + M;
- if (i <= N - M)
- {
- goto D;
- }
- return(*(*(Vi + t) + u));
- }
- int main()
- {
- int beg, end, b, k, t;
- x = fopen("x.txt", "r");
- if (x == NULL)
- {
- printf("Error1\n");
- }
- else
- {
- printf("The file is opened for reading.\n");
- }
- y = fopen("y.txt", "w");
- if (y == NULL)
- {
- printf("Error2\n");
- }
- else
- {
- printf("The file is opened for writing.\n");
- }
- fseek(x, 0L, SEEK_END);
- int N = ftell(x);
- fseek(x, 0L, SEEK_SET);
- for (int h = 0; h<N; h++)
- {
- text[h] = fgetc(x);
- }
- printf("The source text from a file:\r\n");
- printf("%s\r\n", text);
- printf("\r\n");
- while (1)
- {
- printf("Enter the number of words or phrases you want to delete:");
- scanf_s("%d\r\n", &k);
- J:
- if (k > 10 || k <= 0)
- {
- printf("Please the number of words or phrases you want to delete again:");
- scanf_s("%d\r\n", &k);
- goto J;
- }
- if (k <= 10 && k>0)
- {
- break;
- }
- }
- for (int y = 0; y<k; y++)
- {
- gets_s(str[y]);
- }
- printf("\r\n");
- for (int i = 0; i<k; i++)
- {
- for (int j = 0; j<100; j++)
- {
- Vi[i][j] = -6;
- }
- }
- for (t = 0; t<k; t++)
- {
- BM(str, t);
- }
- b = 0;
- for (int i = 0; i < k; i++)
- {
- for (int j = 1; j < 100; j++)
- {
- if (Vi[i][j] >= 0)
- {
- beg = Vi[i][j];
- end = Vi[i][j] + Vi[i][0];
- if (text[end] == ' ')
- {
- end++;
- }
- else if ((text[end] != ' ') && (text[beg - 1] == NULL || text[beg - 2] == '.' || text[beg - 2] == '?' || text[beg - 2] == '!'))
- {
- end = end + 2;
- }
- else if (text[end] != ' ' && text[beg - 1] == ' ')
- {
- beg--;
- }
- for (int y = beg; y < end; y++)
- {
- del[b] = y;
- b++;
- }
- }
- }
- }
- int v = 0;
- for (int m = 0; m < N; m++)
- {
- int R;
- R = OR(m, b);
- if (R == 0)
- {
- text1[v] = text[m];
- v++;
- }
- }
- printf("New text:\r\n");
- printf("%s\r\n", text1);
- printf("\r\n");
- for (int p = 0; p<N; p++)
- {
- fputc(text1[p], y);
- }
- fclose(x);
- fclose(y);
- int n = _fcloseall();
- printf("Numbers of files closed by _fcloseall: %u\n", n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement