fojtasd

Untitled

Dec 6th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #ifndef __PROGTEST__
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <fstream>
  5. #endif /* __PROGTEST__ */
  6.  
  7. using namespace std;
  8.  
  9. int evenOdd(const char * srcFileName, const char * dstFileName)
  10. {
  11.     ifstream input = ifstream("C:\\Users\\fojtas\\source\\repos\\test\\test\\test.txt");
  12.     ofstream output = ofstream("testOut.txt");
  13.     int step = 0;
  14.  
  15.     input = ifstream("C:\\Users\\fojtas\\source\\repos\\test\\test\\test.txt");
  16.     while (input.eof() == 0)
  17.     {
  18.         int check = 0;
  19.         input >> check;
  20.         if ((input.fail() == 1) && (input.bad() == 0)) //detekuje pismeno a zalomeni radku
  21.         {
  22.             if (input.eof() == 1) //pokud jde pouze o zalomeni, vyskoci z cyklu a pokracuje v hledani sudych a lichych cisel
  23.             {
  24.                 break;
  25.             }
  26.             else
  27.                 return 0;
  28.         }
  29.         ++step;
  30.     }
  31.     input.close();
  32.  
  33.     //projde vstupni soubor a vypise suda cisla do vystupniho souboru
  34.     input = ifstream("C:\\Users\\fojtas\\source\\repos\\test\\test\\test.txt");
  35.    
  36.     while (step!=0)
  37.     {
  38.         int a = 0;
  39.         input >> a;
  40.         step--;
  41.         if ((a % 2) == 0)
  42.         {
  43.             output << a << endl;
  44.         }
  45.     }
  46.     input.close();
  47.  
  48.     //projde vstupni soubor a vypise licha cisla do vystupniho souboru
  49.     input = ifstream("C:\\Users\\fojtas\\source\\repos\\test\\test\\test.txt");
  50.     while (input.eof() == 0)
  51.     {
  52.         int a = 0;
  53.         input >> a;
  54.  
  55.         if (((a % 2) > 0) || ((a % 2) < 0))
  56.         {
  57.             output << a << endl;
  58.         }
  59.     }
  60.     input.close();
  61.     output.close();
  62.     return 1;
  63. }
  64.  
  65.  
  66. #ifndef __PROGTEST__
  67. int main(int argc, char * argv[])
  68. {
  69.  
  70.     if (evenOdd("test.txt", "testOut.txt") == 0)
  71.     {
  72.         return 1; //doslo k chybe (chyba v souboru, etc)
  73.         cout.flush();
  74.         getchar();
  75.     }
  76.     else
  77.     {
  78.         return 0; //nedoslo k chybe, funkce dokoncila svuj udel
  79.         cout.flush();
  80.         getchar();
  81.     }
  82.    
  83. }
  84. #endif /* __PROGTEST__ */
Advertisement
Add Comment
Please, Sign In to add comment