Yankeelandy
asked on
Method for reading in command line options
Just wondering if there is a tried and true method for reading in command line options/flags. Are there funcitons out there for searching argv? I could write one myself, but I was just wondering if any documentation existed on this topic.
Thanks,
Jake
Thanks,
Jake
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Nothing has happened on this question in more than 10 months. It's time for cleanup!
My recommendation, which I will post in the Cleanup topic area, is to
split points between akshayxx and snewo.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jmcg
EE Cleanup Volunteer
My recommendation, which I will post in the Cleanup topic area, is to
split points between akshayxx and snewo.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jmcg
EE Cleanup Volunteer
Try this,
if( argc > 1 )
{
int x, r;
for( x = 1; x < argc; x++ )
{
r = options( argv[x] );
if( !r )
printf("\nUnrecognized switch.\n\n");
}
}
...
int options( char* args )
{
int r = 0;
if( strlen( args ) > 2 && args[0] == '-' )
return r;
switch( tolower( args[1] ) )
{
case 'd':
//insert code here
r = 1;
break;
default:
break;
}
return r;
}
Simply add more case statements to add additional flags.
Exceter