home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / learn / args.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-25  |  1.1 KB  |  34 lines

  1. /* ARGS.C illustrates the following variables used for accessing
  2.  * command-line arguments and environment variables:
  3.  *      argc            argv            envp
  4.  *
  5.  * Also illustrates getting a process ID with:
  6.  *      getpid
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <process.h>
  11.  
  12. main( int argc,             /* Number of strings in array argv          */
  13.       char *argv[],         /* Array of command-line argument strings   */
  14.       char **envp )         /* Array of environment variable strings    */
  15. {
  16.     int count;
  17.  
  18.     /* Display each command-line argument. */
  19.     printf( "\nCommand-line arguments:\n" );
  20.     for( count = 0; count < argc; count++ )
  21.         printf( "  argv[%d]   %s\n", count, argv[count] );
  22.  
  23.     /* Display each environment variable. */
  24.     printf( "\nEnvironment variables:\n" );
  25.     while( *envp != NULL )
  26.         printf( "  %s\n", *(envp++) );
  27.  
  28.     /* If run from DOS, shows different ID for DOS than for DOS shell.
  29.      * If execed or spawned, shows ID of parent.
  30.      */
  31.     printf( "\nProcess id of parent: %d", getpid() );
  32.     exit( 0 );
  33. }
  34.