Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int getTerms(FILE* file1, char** terms1)
  6. {
  7.     char* term = (char*)malloc(10000);
  8.     int currLen = 0, read, termsC1 = 0;
  9.  
  10.     while (!feof(file1))
  11.     {
  12.         fscanf(file1, "%s", term + currLen);
  13.         currLen += strlen(term + currLen);
  14.         if (term[currLen - 1] == '.')
  15.         {
  16.             currLen = 0;
  17.             terms1[termsC1] = term;
  18.             term = (char*)malloc(10000);
  19.             termsC1++;
  20.             fseek(file1, 1, SEEK_CUR);
  21.         }
  22.         else
  23.         {
  24.             term[currLen] = ' ';
  25.             currLen++;
  26.         }
  27.     }
  28.  
  29.     return termsC1;
  30. }
  31.  
  32. int main(int argc, char** const args)
  33. {
  34.     FILE* file1 = fopen("Eng.txt", "r");
  35.     FILE* file2 = fopen("Rus.txt", "r");
  36.     FILE* output = fopen("Output.txt", "w");
  37.  
  38.     char** terms1 = (char**)malloc(sizeof(int) * 1000);
  39.     char** terms2 = (char**)malloc(sizeof(int) * 1000);
  40.  
  41.     int termsC = getTerms(file1, terms1);
  42.     getTerms(file2, terms2);
  43.  
  44.     for (int i = 0; i < termsC; ++i)
  45.         fprintf(output, "%d) %s (%s)\n", i+1, terms1[i], terms2[i]);
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement