Solution for Exercise 15-4

ex1504

#include <stdio.h>

int main(int argc, char *argv[])
{
    int x;

    for(x=0;x<argc;x++)
        printf("Arg#%d = %s\n",x+1,argv[x]);
    return(0);
}

Notes

* In Code::Blocks, you need to use the Project→Set Programs' Arguments command to supply the program with command line arguments.

* The value of argc is used in the for statement at Line 7.

* Again, the x+1 convention is used in Line 8 so that humans reading the output won't be confused by element zero in the string array.