#ifndef _IOSTREAM_H #define _IOSTREAM_H #include #include using namespace std; int main(int argc, char* argv[]) { if (argc == 1) //if no argument is passed { cerr << "Usage: test [option]\n"; return 1; } int range1, range2, range[10], i = 0; string temp, arg(argv[1]); //here's the really messy part. The program first checks whether the argument contains a ','. If yes, it then checks for a '-'. If yes, it handles the argument accordingly. while (arg.length() > 0) if (arg.find(",") < arg.length()) if (arg.find("-") < arg.length()) { int loc = arg.find_first_of(",-"); switch (arg[loc]) { case '-': arg.replace(loc, 1, "%"); temp = arg.substr(0, loc); range1 = atoi(temp.c_str()); int nextloc; nextloc = arg.find_first_of("-,"); if (nextloc < arg.length()) { temp = arg.substr(loc + 1, nextloc - loc - 1); arg.erase(0, nextloc + 1); } else { temp = arg.substr(loc + 3); arg.erase(0, loc + 1); } range2 = atoi(temp.c_str()); while (range1 <= range2) range[i++] = range1++; break; case ',': arg.replace(loc, 1, "%"); temp = arg.substr(0, loc); range[i++] = atoi(temp.c_str()); arg.erase(0, loc + 1); break; } } else { int loc = arg.find(","); temp = arg.substr(0, loc); range[i++] = atoi(temp.c_str()); arg.erase(0, loc + 1); } else if (arg.find("-") < arg.length()) { int loc = arg.find("-"); temp = arg.substr(0, loc); range1 = atoi(temp.c_str()); temp = arg.substr(loc + 1, arg.length() - loc - 1); range2 = atoi(temp.c_str()); while (range1 <= range2) range[i++] = range1++; arg.erase(0, loc + 3); } else { range[i++] = atoi(arg.c_str()); break; } //while ends here --i; cout << "Ranges entered:\n"; for(int j = 0; j <= i; j++) cout << range[j] << endl; return 0; } #endif //whew. That took me a long time. Anyway, thank God it's done. Feel free to try it out with various combinations, although I believe I've tried out pretty much every combination. Please do inform me of any bugs.