|
|
1.1 root 1: #print
2: Of course, you can also search for lines that
3: contain backslashes; again, it's simply a matter
4: of doubling the backslash in the search pattern.
5: That is,
6: /\\/
7: finds the next line with a backslash.
8:
9: Find the second occurrence of "\n\n" in the file
10: "prog.c", and type "answer N", where N is its
11: line number.
12: #create prog.c
13:
14: int nsave = 0;
15:
16: selunit()
17: {
18: char fnam[20], s[50];
19: static char dobuff[50];
20: char posslev[20][20];
21: int diff[20], i, k, m, n, best, alts, statb[20];
22: FILE *f;
23: char zb[200];
24: static char saved[20];
25:
26: while (ask) {
27: printf("What lesson? ");
28: fflush(stdout);
29: gets(dobuff);
30: if (strcmp(dobuff, "bye") == 0)
31: wrapup(0);
32: level = todo = dobuff;
33: sprintf(s, "../L%s", dobuff);
34: if (access(s, 04) == 0)
35: return;
36: printf("no such lesson\n");
37: }
38: alts = 0;
39: retry:
40: f=scrin;
41: if (f==NULL) {
42: sprintf(fnam, "../L%s", level);
43: f = fopen(fnam, "r");
44: if (f==NULL) {
45: fprintf(stderr, "No script for lesson %s.\n", level);
46: wrapup(1);
47: }
48: while (fgets(zb, 200, f)) {
49: trim(zb);
50: if (strcmp(zb, "#next")==0)
51: break;
52: }
53: }
54: if (feof(f)) {
55: printf("Congratulations\n\n.You have finished this sequence.\n");
56: fflush(stdout);
57: todo = 0;
58: return;
59: }
60: for(i=0; fgets(s, 50, f); i++) {
61: sscanf(s, "%s %d", &posslev[i], &diff[i]);
62: }
63: best = -1;
64: /* cycle through lessons from random start */
65: /* first try the current place, failing that back up to
66: last place there are untried alternatives (but only one backup) */
67: n = grand()%i;
68: for(k=0; k<i; k++) {
69: m = (n+k)%i;
70: if (already(posslev[m])) continue;
71: if (best<0) best=m;
72: /* real alternatives */
73: alts++;
74: if (abs(diff[m]-speed) < abs(diff[best]-speed))
75: best=m;
76: }
77: if (best < 0 && nsave) {
78: nsave--;
79: strcpy(level, saved);
80: goto retry;
81: }
82: if (best <0) {
83: /* lessons exhausted or missing */
84: printf("Sorry, there are no alternative lessons at this stage.\n");
85: printf("See someone for help.\n\n");
86: fflush(stdout);
87: todo = 0;
88: return;
89: }
90: strcpy (dobuff, posslev[best]);
91: if (alts>1) {
92: nsave=1;
93: strcpy (saved, level);
94: }
95: todo = dobuff;
96: fclose(f);
97: }
98:
99: abs(x)
100: {
101: return(x>=0? x: -x);
102: }
103:
104: grand()
105: {
106: static int garbage;
107: int a[2], b;
108:
109: time(a);
110: b = a[1]+10*garbage++;
111: return(b&077777);
112: }
113: #copyin
114: #user
115: #uncopyin
116: #match 73
117: #bad 43
118: The second______ one.
119: #log
120: #next
121: 44.1h 10
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.