1: 
   2: static char sccsid[] = "	number.c	4.1	82/10/24	";
   3: 
   4: int flag;
   5: int max = 21;
   6: char    *card[] =
   7: {
   8:     "hundred",
   9:     "thousand",
  10:     "million",
  11:     "billion",
  12:     "trillion",
  13:     "quadrillion",
  14:     "quintillion",
  15:     "sextillion",
  16:     "septillion",
  17:     "octillion",
  18:     "nonillion",
  19:     "decillion",
  20:     "undecillion",
  21:     "duodecillion",
  22:     "tredecillion",
  23:     "quattuordecillion",
  24:     "quindecillion",
  25:     "sexdecillion",
  26:     "septendecillion",
  27:     "octodecillion",
  28:     "novemdecillion",
  29:     "vigintillion"
  30: };
  31: char *unit[] = {
  32:     "zero",
  33:     "one",
  34:     "two",
  35:     "three",
  36:     "four",
  37:     "five",
  38:     "six",
  39:     "seven",
  40:     "eight",
  41:     "nine"
  42: };
  43: char *teen[] = {
  44:     "ten",
  45:     "eleven",
  46:     "twelve",
  47:     "thirteen",
  48:     "fourteen",
  49:     "fifteen",
  50:     "sixteen",
  51:     "seventeen",
  52:     "eighteen",
  53:     "nineteen"
  54: };
  55: char *decade[] = {
  56:     "zero",
  57:     "ten",
  58:     "twenty",
  59:     "thirty",
  60:     "forty",
  61:     "fifty",
  62:     "sixty",
  63:     "seventy",
  64:     "eighty",
  65:     "ninety"
  66: };
  67: char    line[100];
  68: main()
  69: {
  70:     register c, i, fraction;
  71:     int r;
  72: 
  73: 
  74:     fraction = 0;
  75:     while(c = getchar()) {
  76:         if(!digit(c))  {
  77:             fraction = (c == '.');
  78:             putchar(c);
  79:             continue;
  80:         }
  81:         if(fraction) {
  82:             while(digit(c)) {
  83:                 putchar(' ');
  84:                 putchar(c);
  85:                 if(!(c=getchar()))
  86:                     exit(1);
  87:             }
  88:             putchar(' ');
  89:             goto out;
  90:         }
  91: 
  92:         putchar(' ');
  93:         i = 0;
  94:         line[i++] = '0';
  95:         line[i++] = '0';
  96:         while(c == '0')
  97:             if(!(c=getchar()))
  98:                 exit(1);
  99:         while(digit(c)) {
 100:             if(i < 98)
 101:                 line[i++] = c;
 102:             if(!(c=getchar()))
 103:                 exit(1);
 104:         }
 105:         line[i] = 0;
 106:         r = i/3;
 107:         if(r == 0) {
 108:             print("zero");
 109:             goto out;
 110:         }
 111:         conv(line+i-3*r, r);
 112: 
 113: out:
 114:         fraction = (c == '.');
 115:         nline();
 116:         printf("...\n");
 117:         if(c != '\n')
 118:             putchar(c);
 119:     }
 120: }
 121: 
 122: conv(p, c)
 123: char *p;
 124: {
 125: 
 126:     if(c > max) {
 127:         conv(p, c-max);
 128:         print(card[max]);
 129:         nline();
 130:         p += (c-max)*3;
 131:         c = max;
 132:     }
 133:     while(c > 1) {
 134:         c--;
 135:         conv(p, 1);
 136:         cprint(card[c]);
 137:         nline();
 138:         p += 3;
 139:     }
 140:     ones(p[0]);
 141:     cprint(card[0]);
 142:     tens(p);
 143:     ones(p[2]);
 144: }
 145: 
 146: ones(d)
 147: {
 148:     if(d=='0')
 149:         return;
 150:     print(unit[d-'0']);
 151: }
 152: 
 153: tens(p)
 154: char *p;
 155: {
 156: 
 157:     switch(p[1]) {
 158: 
 159:     case '0':
 160:         return;
 161: 
 162:     case '1':
 163:         print(teen[p[2]-'0']);
 164:         p[2] = '0';
 165:         return;
 166:     }
 167: 
 168:     print(decade[p[1]-'0']);
 169: }
 170: 
 171: 
 172: digit(c)
 173: {
 174: 
 175:     if(c < '0' || c > '9')
 176:         return(0);
 177:     return(1);
 178: }
 179: 
 180: nline()
 181: {
 182: 
 183:     if(flag)
 184:         printf(".\n");
 185:     flag = 0;
 186: }
 187: 
 188: cprint(s)
 189: {
 190: 
 191:     if(flag)
 192:         print(s);
 193: }
 194: 
 195: print(s)
 196: {
 197: 
 198:     if(flag)
 199:         printf(" ");
 200:     printf(s);
 201:     flag = 1;
 202: }

Defined functions

conv defined in line 122; used 3 times
cprint defined in line 188; used 2 times
digit defined in line 172; used 3 times
main defined in line 68; never used
nline defined in line 180; used 3 times
ones defined in line 146; used 2 times
print defined in line 195; used 6 times
tens defined in line 153; used 1 times

Defined variables

card defined in line 6; used 3 times
decade defined in line 55; used 1 times
flag defined in line 4; used 5 times
line defined in line 67; used 5 times
max defined in line 5; used 5 times
sccsid defined in line 2; never used
teen defined in line 43; used 1 times
unit defined in line 31; used 1 times
Last modified: 1982-10-25
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1140
Valid CSS Valid XHTML 1.0 Strict