C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
ARGS.C
                                             Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
/* ARGS.C illustrates the following variables used for accessing
 * command-line arguments and environment variables:
 *      argc            argv            envp
 *
 * Also illustrates getting a process ID with function:
 *      _getpid
 */
 
#include <stdio.h>
#include <process.h>
 
void main( int argc,        /* Number of strings in array argv          */
           char *argv[],    /* Array of command-line argument strings   */
           char **envp )    /* Array of environment variable strings    */
{
    int count;
 
    /* Display each command-line argument. */
    printf( "\nCommand-line arguments:\n" );
    for( count = 0; count < argc; count++ )
        printf( "  argv[%d]   %s\n", count, argv[count] );
 
    /* Display each environment variable. */
    printf( "\nEnvironment variables:\n" );
    while( *envp != NULL )
        printf( "  %s\n", *(envp++) );
 
    /* If run from command line, shows different ID depending on whether
     * run from a shell. If execed or spawned, shows ID of parent.
     */
    printf( "\nProcess id of parent: %d", _getpid() );
    exit( 0 );
}
                                    -♦-