------------------------------------------------------------------------------
MC logo
Fancy Plain C Arg Lister (With Pointers)
[^] CSc 220 Home
------------------------------------------------------------------------------
[Introduction] [Boolean and Control] [Functions] [Arrays and Pointers] [Dynamic Arrays] [Array Errors] [Command Array] [Standard Containers] [Structs and Classes] [Automatic Pointer] [Multi-File Programs] [Copying Objects] [Templates] [Inheritance] [Plain C I/O] [Type Odds And Ends] [Plain C Strings] [File I/O]
[C Strings] [More C Strings] [Plain C Arg Lister] [Fancy Plain C Arg Lister (With Pointers)] [Simple String Sort]
listargs2.c
/*
 * This program lists the command line arguments, separating the program
 * name, and creating a fancier output.  It also demonstrates some
 * fancier pointer expressions.
 */
#include <stdio.h>

int main(int argc, char **argv)
{
        char *pname;

        /* Isolate the command name.*/
        pname = *argv++;
        --argc;
        printf("Command: %s.\n", pname);

        /* See if there were any args, and print them if so. */
        if(argc == 0)
                printf("%s: No arguments given (boo hoo).\n", pname);
        else {
                int n = 1;
                while(argc--)
                        printf("Arg %d to %s: %s\n", n++, pname, *argv++);
        }
}