/*
  Example of strtoimax(): convert a command-line argument to its integer value.

  Bill Slough
  MAT 4970
*/

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#define BASE 10   /* Desired base to be used during conversion */

int main(int argc, char *argv[]) {
    if (argc != 2) {
	/* Exactly two command-line arguments are expected; complain and quit. */
	fprintf(stderr, "Usage: %s integer\n", argv[0]);
	return 1;
    }

    /* Convert the command-line argument to its equivalent integer value */
    char *endptr;
    int convertedValue = strtoimax(argv[1], &endptr, BASE);

    /* Ensure that only digits were encountered during the conversion */
    if (*endptr == '\0')
	printf("Command line argument is %d\n", convertedValue);
    else
	printf("Integer value expected.\n");

    return 0;
}
