#include <stdio.h>
#define NAME "getnum"
#define VERSION "2.0"

main(argc,argv)
int argc;
char *argv[];
{

	long maxwait;
	long t0,t1;
	int c;
	if (argc<2){
		printf("By Andrew Gaunt, AKA Quantum, #1@6300 - May be freely shared.\n\n");
		printf("usage: getnum timeout\n\n");
		printf("If a key is pressed within timeout seconds, getnum will exit\n");
		printf("The error level set a specific value.\n\n");
		printf("If the key pressed is a number from 1-9, the error level will\n");
		printf("be set to 1-9, respectively. Any other key pressed will set it\n");
		printf("to 10. It timeout seconds is exceeded, it will be 0\n");
		printf("\n[%s v%s]\n",NAME,VERSION);
	}
	maxwait=atol(argv[1]);
	time(&t0);
	while (!kbhit()) {
		time(&t1);
		if(t1>t0+maxwait){
			exit(0);
		}
	}
	c=getch();
	c-=48;
	if (c>0 && c<10)
		exit(c);
	exit(10);
}


