Command-Line Arguments

Let the run carry its settings.

Access command-line arguments from model code. Review the interface and examples while preserving exact argument-handling syntax.

Accessing Command-line Arguments from Models


How do you access the command-line arguments from the sim.exe command-line, from within a model?

There is a global data structure defined:

         struct argtype
          {
           int argc;
           char **argv;
          };

And there is a global variable: globargs

         struct argtype  *globargs;

... Which points to the args.
You can access them from within a model as, for example:

        {
         int argc;      /* To hold the number of args. */
         char **argv;   /* To hold the array of argument strings. */

         argc = globargs->argc;
         argv = globargs->argv;

         j = 1;
     while (j < argc)
      {
        printf(" arg%d = /%s/\n", j, argv[j] );
        j = j + 1;
      }
        }

This is consistent with the method decribed in K&R (pg. 114, Kernighan-Ritchie) as with main(int argc, char *argv[]) .


ret

This page is an editorial rewrite of source documentation. Historical status, availability, and platform notes are not independently verified for a current release. Technical examples are reference material, not a live simulator.