I cant seem to obtain multiple command line arguments using getopt_long(). my code segfaults after it prints 1. I have another way to parse command line but it s killing me that this isnt working. Its so simple. Any ideas? thanks
int main(int argc, char** argv) {
int val;
std::string clcf;
int futures (0), blocks(0);
static struct option long_options[] =
{
{ "config" , required_argument , 0 , 'c' },
{ "sstest" , optional_argument , 0 , 's' },
{ "btest" , optional_argument , 0 , 'b' },
//{ "ssfspreads" , optional_argument , 0 , 'S' },
//{ "blockspreads" , optional_argument , 0 , 'B' },
{ 0 , 0 , 0 , 0 }
};
while ((val = getopt_long (argc, argv, GETARGLIST.c_str(), long_options, 0)) != -1)
{
switch (val)
{
case 'c': clcf = optarg; break;
case 's':
std::cout << "1" << std::endl;
futures = atoi( optarg ); break;
std::cout << "2" << futures << std::endl;
break;
case 'b':
std::cout << "1" << std::endl;
//blocks = atoi(optarg);
break;
//case 'ss': ssf_spreads = get_value<unsigned>(optarg); break;
//case 'bs': block_spreads = get_value<stdunsigned>(optarg); break;
default: break;
}
}