Listing 9
/*
* checknum.c: written by Leor Zolman
* Convert argument to number on standard output, or ERROR if none
*
* Compile:
* cc checknum.c -o checknum
*/
#include <stdio.h>
main(argc,argv)
char **argv;
{
int nvals, n;
if (argc < 2)
{
fprintf(stderr,"usage: %s text\n", argv[0]);
puts("ERROR");
exit (1);
}
nvals = sscanf(argv[1], "%d", &n);
if (!nvals)
{
puts("ERROR");
exit (1);
}
else
{
printf("%d", n);
exit (0);
}
}
|