abubaca

Untitled

Feb 15th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.     if (argc != 2)
  9.     {
  10.         cout << "Please enter file to analysis as a command line argument" << endl;
  11.         cin.get();
  12.         return 0;
  13.     }
  14.     ifstream data(argv[1]);
  15.     if (!data.is_open())
  16.     {
  17.         cout << "File not found!" << endl;
  18.         cin.get();
  19.         return 0;
  20.     }
  21.     ofstream out("out.txt");
  22.     if (!out.is_open())
  23.     {
  24.         cout << "Could not create/edit output file" << endl;
  25.         cin.get();
  26.         return 0;
  27.     }
  28.     int flag = 0;
  29.     char temp;
  30.     while (!data.eof())
  31.     {
  32.         data >> temp;
  33.         switch (flag)
  34.         {
  35.         case 0:
  36.             if ((temp == '(') || (temp == ')') || (temp == '{') || (temp == '}') || (temp == '[') || (temp == ']'))
  37.                 out << temp;
  38.             else
  39.                 if (temp == '-')
  40.                     flag = 1;
  41.                 else
  42.                     if (temp == '0' || temp == '1' || temp == '2' || temp == '3' || temp == '4' || temp == '5' || temp == '6' || temp == '7' || temp == '8' || temp == '9')
  43.                         flag = 2;
  44.             break;
  45.         case 1:
  46.             if (temp == '0' || temp == '1' || temp == '2' || temp == '3' || temp == '4' || temp == '5' || temp == '6' || temp == '7' || temp == '8' || temp == '9')
  47.             {
  48.                 flag = 2;
  49.                 out << '-' << temp;
  50.             }
  51.             else
  52.                 flag = 0;
  53.             break;
  54.         case 2:
  55.             if (temp == '0' || temp == '1' || temp == '2' || temp == '3' || temp == '4' || temp == '5' || temp == '6' || temp == '7' || temp == '8' || temp == '9')
  56.                 out << temp;
  57.             else
  58.                 flag = 0;
  59.             break;
  60.         }
  61.     }
  62.     cout << "Jobe done" << endl;
  63.     cin.get();
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment