/*--------------------------------------------------------------------
 * Program: prog_arg.c
 * Author : Prof. Joseph K. Ng
 * Description: This program demonstration how to get command line 
 *              arguments into the program.
 * To compile: gcc -o prog_arg prog_arg.c
 * To run: prog_arg 10 9.8 A Joseph
 *-------------------------------------------------------------------*/
#include <stdio.h>  /* for printf( ) */
#include <string.h> /* for strcpy( ) */
#include <stdlib.h> /* for atoi( ) and atof( ) */

int main(int argc, char* argv[])
{
 int i;
 float x;
 char c;
 char word[10];

 if (argc < 4){ /* if there are less than 4 arguments */
    printf("Usage: %s <integer> <float> <char> <word>\n", argv[0]);
    exit(1); /* exit with errorlevel = 1 */
 }

 i = atoi(argv[1]);
 x = atof(argv[2]);
 c = argv[3][0];
 strcpy(word, argv[4]);

 printf("Integer i : %d\n", i);
 printf("Floating Point x : %f\n", x);
 printf("Character c : %c\n", c);
 printf("String word : %s\n", word);

 return 0; /* exit with errorlevel = 0 */
}

