Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main(int argc, char *argv[])
- {
- if (argc != 2)
- {
- cout << "Please enter file to analysis as a command line argument" << endl;
- cin.get();
- return 0;
- }
- ifstream data(argv[1]);
- if (!data.is_open())
- {
- cout << "File not found!" << endl;
- cin.get();
- return 0;
- }
- ofstream out("out.txt");
- if (!out.is_open())
- {
- cout << "Could not create/edit output file" << endl;
- cin.get();
- return 0;
- }
- int flag = 0;
- char temp;
- while (!data.eof())
- {
- data >> temp;
- switch (flag)
- {
- case 0:
- if ((temp == '(') || (temp == ')') || (temp == '{') || (temp == '}') || (temp == '[') || (temp == ']'))
- out << temp;
- else
- if (temp == '-')
- flag = 1;
- else
- if (temp >= '0' && temp <='9')
- {
- out << temp;
- flag = 2;
- }
- break;
- case 1:
- if (temp >= '0' && temp <= '9')
- {
- flag = 2;
- out << '-' << temp;
- }
- else
- {
- flag = 0;
- if ((temp == '(') || (temp == ')') || (temp == '{') || (temp == '}') || (temp == '[') || (temp == ']'))
- out << temp;
- }
- break;
- case 2:
- if (temp >= '0' && temp <= '9')
- out << temp;
- else
- {
- flag = 0;
- if ((temp == '(') || (temp == ')') || (temp == '{') || (temp == '}') || (temp == '[') || (temp == ']'))
- out << temp;
- }
- break;
- }
- }
- cout << "Jobe done" << endl;
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment