ok, I'm trying to get this to work but somehow can't figure it out.
I want to distinguis between flags in a command line. These are the flags that the prog can use
[-norand] [-ncols] [-nrows] [-n N]
so basically a command could look like:
user~> main -norand -ncols 5 -nrows 6
or
user~> main -nrows 3 -n 5
the program goes into an infite loop on every flag except -norand...on norand it just hangs.....here is the code.
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
#include "grid.h"
void get_arguments(int arg, char *argv[], bool &random,
int &r, int &c, int &n)
{
if(arg == 1){
return;
}else{
while( (arg -= 2) > 0 ){
switch (argv[ 1][ 2]) { /* handle options */
case 'o':
random = true;
cout << "rand" << endl;
break;
case 'c':
c = atoi( argv[ 2]);
cout << "cols" << endl;
break;
case 'r':
r = atoi(argv[ 2]);
cout << "rows" << endl;
break;
case ' ':
n = atoi(argv[ 2]);
cout << "N " << n << endl;
break;
}
arg += 2;
}
}
}
int main(int argc, char *argv[])
{
bool random = true;
int rows = 0;
int cols = 0;
int n = 0;
get_arguments(argc, argv, random, rows, cols, n);
return 0;
}
yhanks, axon