Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <locale.h>
- #include <iostream>
- using namespace std;
- char* checker(FILE *&f, char word[])
- {
- fseek(f, 0, SEEK_SET);
- char w1[100], w2[100];
- while (!feof(f))
- {
- fscanf(f, "%s", w1);
- fscanf(f, "%s", w2);
- if(w1[strlen(w1) - 1] == ',')
- w1[strlen(w1) - 1] = '\0';
- if (w2[strlen(w2) - 1] == ',')
- w2[strlen(w2) - 1] = '\0';
- if (!strcmp(w1, word))
- return w2;
- }
- return NULL;
- }
- int main()
- {
- FILE * f1 = fopen("text.txt", "r");
- FILE * f2 = fopen("words.txt","r");
- FILE * g = fopen("answer.txt", "w+");
- char word[100];
- bool znak;
- char *c = (char *)malloc(sizeof(char) *2);
- c[1] = '\0';
- while (!feof(f1))
- {
- znak = false;
- fscanf(f1, "%s", word);
- if (word[strlen(word) - 1] == ',' || word[strlen(word) - 1] == '.' || word[strlen(word) - 1] == '!'|| word[strlen(word) - 1] == '&')
- {
- znak = true;
- c[0] = word[strlen(word) - 1];
- word[strlen(word) - 1] = '\0';
- }
- if (checker(f2, word) != NULL)
- {
- char w[100];
- strcpy(w, checker(f2, word));
- if (znak)
- {
- strcat(w, c);
- }
- fprintf(g, "%s ", w);
- }
- else
- {
- if (znak)
- {
- strcat(word, c);
- }
- fprintf(g, "%s ", word);
- }
- }
- fclose(f1);
- fclose(f2);
- fclose(g);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement