home *** CD-ROM | disk | FTP | other *** search
- /*
- By Michael M. Cherson 3/13/88
-
- ARG.C: Demonstrates the use of 'argc'
- to display all command line variables,
- how to assign strings, and the
- correct way to use pointers and strcpy
- */
-
- #include <stdio.h>
- #include <string.h>
-
- main(argc, argv)
-
- int argc;
- char *argv[];
-
- {
- char name[80], *name2, *name3; /* note name[80] is an array while name2 is */
- int i = 0; /* a pointer */
-
- while (argv[i] != NULL) /* loop until NULL string found */
- { /* display argv index and
- command line variable */
-
- printf("\nargv[%d]: %s",i,argv[i]); /* print all cmd line arguments */
-
- i++; /* bump index to argv */
- }
- strcpy(name,argv[1]);
- printf("\n%s",name); /* display copied string */
-
- name2 = argv[2];
- printf("\nargv[2]= %s", name2);
-
- name3 = name;
- printf("\nname3= %s", name3);
- }