/* Roll the I-ching. * Rewritten from a ada program late one night when I had nothing * else to do but glare at levee, by David Parsons. * Even if I could copyright it, I couldn't take the loss * of self-respect. */ #include #define STRINGLGTH 40 typedef char hexagram[6]; typedef char short_string[STRINGLGTH]; hexagram hex; int hex_number; short_string s1, s2, s3, s4; int i, hex_num; FILE *dat, *fopen(); #define put(s) fputs(s, stdout) throw_i_ching (hex_number, h) hexagram h; int *hex_number; { int flips = rand(); *hex_number = (1+flips) % 64; for (i=0; i<6; i++) h[i] = flips & (1<9) putchar('-'); else putchar(' '); } /*put_broken_line*/ put_hexagram (h) hexagram h; { register i; for (i = 0; i < 6; i++) { if (h[i]) put_solid_line(); else put_broken_line(); putchar('\n'); } } /*put_hexagram*/; main() { char scratch[80]; long timex; time(&timex); srand((unsigned)timex); if (dat = fopen("c:/lib/i_ching.dat", "r")) { putchar('\n'); throw_i_ching(&hex_num, hex); /* flip the tokens */ put_hexagram (hex); /* and display the results */ while (hex_num > 0) { /* skip to expected hexagram */ for (i = 0; i< 4; i++) fgets(scratch, 80, dat); hex_num = hex_num - 1; } fgets (s1, STRINGLGTH-1, dat); /* read data on the hexagram */ fgets (s2, STRINGLGTH-1, dat); fgets (s3, STRINGLGTH-1, dat); fgets (s4, STRINGLGTH-1, dat); put ("\nHexagram: "); put (s1); /* strings have \n already */ put ("Name: "); put (s2); put ("Meaning: "); put (s3); put (" "); put ("the symbol of\n"); put (" "); put (s4); } }