O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Code Sample 9.1: Searching Command-Line Supplied Parameters

This function extracts a value from the command line, based on a supplied parameter:

// Purpose : to return the value associated with a // specific parameter from an array of strings. // The assumption is : // that each <parameter> starts with '-'. The string // TRUE is returned if a parameter is found, with no // value associated with it. char * GetParameterValue ( char ** szCommandLine, char * szParameter, int nParameters ) { int nParameter = 1; // Check that we had some parameters supplied if ( nParameters-1 < nParameter ) return NULL; do { // Check to see if nParameter starts with '-' if ( szCommandLine[nParameter][0] == '-' ) { // Does it match? if ( strcmp( szCommandLine[nParameter], ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required