main(int argc, char **argv)
{
int i, j;
j = 0;
while(argc > 0) {
i = j + 5;
j = main(b(j), i-1);
}
}
UNIX> cd /mahogany/homes/plank UNIX> pwd /mahogany/homes/plank UNIX> parent plank UNIX> cd papers UNIX> pwd /mahogany/homes/plank/papers UNIX> parent papers UNIX>See the last page of this test for prototypes of C library calls and system calls that may be helpful.
UNIX> cd / UNIX> parent
Thus, for the following file:
UNIX> cat geh # Beginning I am Sam I am Sam Sam I am That Sam I am That Sam I am I do not like that Sam I am # end UNIX>The output of the program should be the following:
UNIX> wordline < geh I: 2, 3, 4, 5 Sam: 2, 3, 4, 5 That: 5 am: 2, 3, 4, 5 do: 5 like: 5 not: 5 that: 5 UNIX>Now, behold the following code for printword:
#include < stdio.h >
#include "fields.h"
#include "rb.h"
main()
{
IS is;
Rb_node t, tmp;
char *s;
int i, fnd;
t = make_rb();
is = new_inputstruct(NULL);
while(get_line(is) > 0) {
if (is->text1[0] != '#') {
for (i = 0; i < is->NF; i++) {
tmp = rb_find_key_n(t, is->fields[i], &fnd);
if (!fnd || is->line != (int) (tmp->v.val)) {
rb_insert(t, is->fields[i], (char *) (is->line));
}
}
}
}
s = NULL;
rb_traverse(tmp, t) {
if (strcmp(s, tmp->k.key) != 0) {
if (s != NULL) printf("\n");
printf("%s: %d", tmp->k.key, (int) (tmp->v.val));
} else {
printf(", %d", (int) (tmp->v.val));
}
s = tmp->k.key;
}
printf("\n");
}
There are five bugs in this program. By ``bug'', I mean that they
will cause incorrect output (or core dumpage), not inefficiency.
Four of them are simple
and can be fixed within the line that they occur. The fifth is
a disign flaw in the program. For each of these bugs:
Again, prototypes of relevant C functions and structs are at the end of the test.