Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
- int sravn(char* word1, char* word2, int n);
- int sravn(char* word1, char* word2, int n)
- {
- for (int i = 0; i < n; i++) {
- if (word1[i] != word2[i]) {
- return 0;
- }
- }
- return 1;
- }
- int main(void) {
- FILE* fin;
- FILE* fout;
- char start[4001];
- char end[4001];
- char word[4001];
- int sym, i = 0, lens = 0, lene = 0, lenw = 0;
- int between_brackets = 0;
- if ((fin = fopen("input.txt", "r")) == NULL)
- {
- printf("cannot open input file!\n");
- return -1;
- }
- if ((fout = fopen("output.txt", "w")) == NULL)
- {
- printf("cannot open output file!\n");
- fclose(fin);
- return -1;
- }
- while ((sym = fgetc(fin)) != EOF && !isspace(sym)) //считали W
- {
- start[i] = sym;
- i++;
- lens++;
- }
- printf("left skobka: ");
- for (i = 0; i < lens; i++) {
- putchar(start[i]);
- }
- printf("\n");
- i = 0;
- while ((sym = fgetc(fin)) != EOF && !isspace(sym)) //считали W
- {
- end[i] = sym;
- i++;
- lene++;
- }
- printf("\n");
- printf("right skobka: ");
- for (i = 0; i < lens; i++) {
- putchar(end[i]);
- }
- i = 0;
- printf("\n");
- while ((sym = fgetc(fin)) != EOF)
- {
- if (!isspace(sym))
- {
- word[i] = sym;
- //putchar(sym);
- lenw++;
- i++;
- }
- else if (!between_brackets && lenw == lens)
- {
- if (sravn(word, start, lenw) == 1) {
- between_brackets = 1;
- lenw = 0;
- }
- }
- else if ((between_brackets && lenw == lene))
- {
- if(sravn(word, end, lenw) == 1) {
- between_brackets = 0;
- lenw = 0;
- }
- }
- else if(!between_brackets)
- {
- for (int q = 0; q < lenw; q++) {
- fputc(word[i], fout);
- }
- lenw = 0;
- }
- }
- fclose(fin);
- fclose(fout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement