Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __PROGTEST__
- #include <iostream>
- #include <cstdlib>
- #include <fstream>
- #endif /* __PROGTEST__ */
- using namespace std;
- int evenOdd(const char * srcFileName, const char * dstFileName)
- {
- ifstream input = ifstream("C:\\Users\\fojtas\\source\\repos\\test\\test\\test.txt");
- ofstream output = ofstream("testOut.txt");
- int step = 0;
- input = ifstream("C:\\Users\\fojtas\\source\\repos\\test\\test\\test.txt");
- while (input.eof() == 0)
- {
- int check = 0;
- input >> check;
- if ((input.fail() == 1) && (input.bad() == 0)) //detekuje pismeno a zalomeni radku
- {
- if (input.eof() == 1) //pokud jde pouze o zalomeni, vyskoci z cyklu a pokracuje v hledani sudych a lichych cisel
- {
- break;
- }
- else
- return 0;
- }
- ++step;
- }
- input.close();
- //projde vstupni soubor a vypise suda cisla do vystupniho souboru
- input = ifstream("C:\\Users\\fojtas\\source\\repos\\test\\test\\test.txt");
- while (step!=0)
- {
- int a = 0;
- input >> a;
- step--;
- if ((a % 2) == 0)
- {
- output << a << endl;
- }
- }
- input.close();
- //projde vstupni soubor a vypise licha cisla do vystupniho souboru
- input = ifstream("C:\\Users\\fojtas\\source\\repos\\test\\test\\test.txt");
- while (input.eof() == 0)
- {
- int a = 0;
- input >> a;
- if (((a % 2) > 0) || ((a % 2) < 0))
- {
- output << a << endl;
- }
- }
- input.close();
- output.close();
- return 1;
- }
- #ifndef __PROGTEST__
- int main(int argc, char * argv[])
- {
- if (evenOdd("test.txt", "testOut.txt") == 0)
- {
- return 1; //doslo k chybe (chyba v souboru, etc)
- cout.flush();
- getchar();
- }
- else
- {
- return 0; //nedoslo k chybe, funkce dokoncila svuj udel
- cout.flush();
- getchar();
- }
- }
- #endif /* __PROGTEST__ */
Advertisement
Add Comment
Please, Sign In to add comment