home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / cmdline / arg / arg1.c next >
Encoding:
C/C++ Source or Header  |  1988-03-13  |  950 b   |  38 lines

  1. /*
  2.     By Michael M. Cherson 3/13/88
  3.  
  4.     ARG.C: Demonstrates the use of 'argc'
  5.     to display all command line variables,
  6.         how to assign strings, and the
  7.     correct way to use pointers and strcpy
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. main(argc, argv)
  14.  
  15. int argc;
  16. char *argv[];
  17.  
  18. {
  19.     char name[80], *name2, *name3;     /* note name[80] is an array while name2 is */
  20.     int i = 0;                 /* a pointer */
  21.  
  22.     while (argv[i] != NULL)    /* loop until NULL string found */
  23.     {                           /* display argv index and
  24.                    command line variable */
  25.  
  26.        printf("\nargv[%d]: %s",i,argv[i]); /* print all cmd line arguments */
  27.  
  28.        i++;                     /* bump index to argv */
  29.     }
  30.     strcpy(name,argv[1]);
  31.     printf("\n%s",name);        /* display copied string */
  32.  
  33.     name2 = argv[2];
  34.     printf("\nargv[2]= %s", name2);
  35.  
  36.     name3 = name;
  37.     printf("\nname3= %s", name3);
  38. }