

char	*trip() , *tack();

char	*dig1[10] = {
	"Zero",
	"One",
	"Two",
	"Three",
	"Four",
	"Five",
	"Six",
	"Seven",
	"Eight",
	"Nine"
};

char	*dig2[10] = {
	"Null",
	"Ten",
	"Twenty",
	"Thirty",
	"Fourty",
	"Fifty",
	"Sixty",
	"Seventy",
	"Eighty",
	"Ninety"
};

char	*ten[10] = {
	"Ten",
	"Eleven",
	"Twelve",
	"Thirteen",
	"Fourteen",
	"Fifteen",
	"Sixteen",
	"Seventeen",
	"Eighteen",
	"Nineteen"
};

char	*den[12] = {
	"",
	"Thousand",
	"Million",
	"Billion",
	"Trillion",
	"Quadrillion",
	"Quintillion",
	"Sextillion",
	"Septillion",
	"Octillion",
	"Nonillion",
	"Decillion"
};

main(c,v)
char **v;
{
	char	buf[512] , *h , tbf[4];
	register char *t , *s;
	register l;
	int ng , i;

	if(c != 2){
		printf("Usage: num #\n");
		exit(1);
	}

	v++;
	s = *v;
	h = buf;
	if(*s == '-') {
		h = tack(h,"Negative");
		s++;
		++(*v);
	}

	while(*s)if(*s == ','){
			t = s;
			while(*t = *(t+1))t++;
		}
		else	if(*s < '0' || *s > '9'){
				printf("Bad character: %c\n",*s);
				exit(2);
			}
			else	s++;

	t = *v;
	while(*t == '0')t++;
	l = s-t;
	if(l == 0)tack(buf,dig1[0]);
	else	{
		ng = (l-1)/3 + 1;
		l =% 3;
		if(l == 0)l = 3;
		while(ng--){
			s = tbf;
			while(l--)*s++ = *t++;
			l = 3;
			*s = 0;
			s = trip(tbf);
			if(*s++ == 0)continue;
			h = tack(h,s);
			h = tack(h,den[ng]);
			*h++ = ',';
		}
	}
	*h = 0;
	if(*(h-1) == ',')*(h-1) = 0;
	printf("%s\n",buf+1);
}


char	*trip(s)
register char *s;
{
	register char *t;
	register l;
	static char nm[128];

	nm[0] = 0;
	while(*s == '0')s++;
	t = s;
	while(*t)t++;
	l = t-s;
	if(l == 0){
		*--s = '0';
		l = 1;
	}
	t = nm;

	if(l == 3){
		t = tack(t,dig1[*s-'0']);
		s++;
		t = tack(t,"Hundred");
		l--;
	}

	if(l == 2){
		if(*s != '0'){
			if(*s == '1'){
				t = tack(t,ten[*(s+1)-'0']);
				return(nm);
			}
			t = tack(t,dig2[*s-'0']);
		}
		s++;
	}

	if(*s == '0')return(nm);
	tack(t,dig1[*s-'0']);
	return(nm);
}

char	*tack(s,t)
register char *s , *t;
{
	*s++ = ' ';
	while(*s = *t++)s++;
	return(s);
}

