/** * exptui.c * A simple user interface for the exponentiation procedures. * Copyright (c) 2010 Samuel A. Rebelsky * Released under GPL 3.0 */ /* +---------+-------------------------------------------------------- * | Headers | * +---------+ */ /* stdlib.h supplies strtol. */ #include /* stdio.h supplies printf and fprintf. */ #include /* errno.h supplies errno, which is used for error checking in strtol. */ #include /* +------+----------------------------------------------------------- * | Main | * +------+ */ int main (int argc, char **argv) { if (argc != 3) { fprintf (stderr, "%s: Expects two parameters, received %d.\n", argv[0], argc); exit (EXIT_FAILURE); } errno = 0; long x = strtol (argv[1], (char **) NULL, 10); if (errno != 0) { fprintf (stderr, "exptui: Invalid parameter: %s.\n", argv[0]); exit (EXIT_FAILURE); } long y = strtol (argv[2], (char **) NULL, 10); if (errno != 0) { fprintf (stderr, "exptui: Invalid parameter: %s.\n", argv[0]); exit (EXIT_FAILURE); } long result = expt (x, y); printf("%d^%d = %d\n", x, y, result); exit (EXIT_SUCCESS); } /* main (int, char **) */