Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.62 KB | None | 0 0
  1. #include<iostream>
  2. #include<locale.h>
  3. #include<stdio.h>
  4.  
  5. #define _CRT_SECURE_NO_WARNINGS
  6. #define INPUT "input.txt"
  7. #define OUTPUT "output.txt"
  8.  
  9. using namespace std;
  10.  
  11.  
  12. struct Word
  13. {
  14.     char ch = 0;
  15.     Word* next;
  16. };
  17.  
  18. struct Line
  19. {
  20.     int count = 0;
  21.     Word* word;
  22.     Line* next;
  23. };
  24.  
  25. void search(Line* line, int find)
  26. {
  27.     Word* wordNow;
  28.     wordNow = line->word->next;
  29.     while (wordNow != NULL)
  30.     {
  31.         if (((int(wordNow->ch)) % 2) == find)
  32.             line->count++;
  33.         printf ("%c", wordNow->ch);
  34.         wordNow = wordNow->next;
  35.     }
  36.     printf  ("<-","\n");
  37.     printf ("%d \n", line->count);
  38. }
  39.  
  40.  
  41. void main()
  42. {
  43.     setlocale(LC_ALL, "Russian");
  44.     char ch = 0;
  45.     int find;
  46.     bool point = false;
  47.  
  48.     //fstream file;
  49.     //file.open(INPUT);
  50.  
  51.     FILE *file;
  52.    
  53.     if (file = fopen("C:\Games\input.txt","r"))
  54.     {
  55.  
  56.         printf ("Четное или нечетное: ");
  57.         scanf_s("%d ",&find);
  58.         find = find % 2;
  59.  
  60.         Line lineFirst;
  61.         Line* lineNow;
  62.         lineNow = &lineFirst;
  63.         lineFirst.word = new Word;
  64.         Word* wordNow = lineFirst.word;
  65.  
  66.         while ((ch != EOF) && (ch != '.'))
  67.         {
  68.             fscanf_s(file, "%c", &ch);
  69.             //printf_s(" 1 %c ", ch);
  70.             if (ch == '.') point = true;
  71.             if ((ch != ' ') && (ch != '.'))
  72.             {
  73.                 wordNow->next = new Word;
  74.                 wordNow = wordNow->next;
  75.                 wordNow->ch = ch;
  76.             }
  77.             else if (wordNow->ch != 0)
  78.             {
  79.                 lineNow->next = new Line;
  80.                 lineNow = lineNow->next;
  81.                 lineNow->word = new Word;
  82.                 wordNow->next = NULL;
  83.                 wordNow = lineNow->word;
  84.             }
  85.         }
  86.         fclose(file);
  87.         wordNow->next = NULL;
  88.         lineNow->next = NULL;
  89.     }
  90.     else {
  91.  
  92.         printf  ("Input file not found!\n");
  93.  
  94.     }
  95.     //scanf("%s ",&ch);
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement