Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAX_PHRASE_LEN 100
  5.  
  6. char source_phrase[MAX_PHRASE_LEN];
  7. int  source_phrase_len;
  8. int  words_in_phrase = 1;
  9.  
  10. int symbols_in_file = 0;
  11.  
  12. void scan_phrase(FILE* fin)
  13. {
  14.     fgets(source_phrase, MAX_PHRASE_LEN, fin);
  15.     source_phrase[strlen(source_phrase) - 2] = 0;
  16.     source_phrase_len = strlen(source_phrase);
  17.     for (int i = 0; i < source_phrase_len; ++i) {
  18.         if (source_phrase[i] == ' ' && source_phrase[i] == '\t') {
  19.             ++words_in_phrase;
  20.         }
  21.     }
  22. }
  23.  
  24. int main()
  25. {
  26.     FILE* fin, * fout;
  27.  
  28.     fopen_s(&fin, "input.txt", "rb");
  29.     fopen_s(&fout, "output.txt", "w");
  30.  
  31.     if (fin == NULL || fout == NULL) {
  32.         return -1;
  33.     }
  34.  
  35.     scan_phrase(fin);
  36.  
  37.     char word[MAX_PHRASE_LEN];
  38.     char phrase[MAX_PHRASE_LEN];
  39.  
  40.     memset(word, 0, MAX_PHRASE_LEN);
  41.     memset(phrase, 0, MAX_PHRASE_LEN);
  42.    
  43.     while (1) {
  44.         for (int i = 0; i < words_in_phrase; ++i) {
  45.             fscanf_s(fin, "%s", word);
  46.             strcat_s(phrase, strlen(word), word);
  47.         }
  48.     }
  49.    
  50.     fclose(fin);
  51.     fclose(fout);
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement