Advertisement
codegod313

Gleb_3

May 29th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <locale.h>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. char* checker(FILE *&f, char word[])
  9. {
  10.     fseek(f, 0, SEEK_SET);
  11.     char w1[100], w2[100];
  12.     while (!feof(f))
  13.     {
  14.         fscanf(f, "%s", w1);
  15.         fscanf(f, "%s", w2);
  16.         if(w1[strlen(w1) - 1] == ',')
  17.             w1[strlen(w1) - 1] = '\0';
  18.         if (w2[strlen(w2) - 1] == ',')
  19.             w2[strlen(w2) - 1] = '\0';
  20.         if (!strcmp(w1, word))
  21.             return w2;
  22.     }
  23.     return NULL;
  24. }
  25.  
  26. int main()
  27. {
  28.     FILE * f1 = fopen("text.txt", "r");
  29.     FILE * f2 = fopen("words.txt","r");
  30.     FILE * g = fopen("answer.txt", "w+");
  31.     char word[100];
  32.     bool znak;
  33.     char *c = (char *)malloc(sizeof(char) *2);
  34.     c[1] = '\0';
  35.     while (!feof(f1))
  36.     {
  37.         znak = false;
  38.         fscanf(f1, "%s", word);
  39.         if (word[strlen(word) - 1] == ',' || word[strlen(word) - 1] == '.' || word[strlen(word) - 1] == '!'|| word[strlen(word) - 1] == '&')
  40.         {
  41.             znak = true;
  42.             c[0] = word[strlen(word) - 1];
  43.             word[strlen(word) - 1] = '\0';
  44.         }
  45.         if (checker(f2, word) != NULL)
  46.         {
  47.             char w[100];
  48.             strcpy(w, checker(f2, word));
  49.             if (znak)
  50.             {
  51.                 strcat(w, c);
  52.             }
  53.             fprintf(g, "%s ", w);
  54.         }
  55.         else
  56.         {
  57.             if (znak)
  58.             {
  59.                 strcat(word, c);
  60.             }
  61.             fprintf(g, "%s ", word);
  62.         }
  63.     }
  64.     fclose(f1);
  65.     fclose(f2);
  66.     fclose(g);
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement