S
Seebs
(Did *anyone* "approve" of that? Dismiss it as a minor fencepost
error of the sort people make when not reviewing or checking code,
sure. *Approve*? I sure don't think so.)
This one's actually fixed in the third edition! That's surprising, since
the 3rd edition seems to have fixed very few bugs.
On the other hand, the example is more fundamentally broken. The structure
of the "scheduler" is an array[MAX] of char *. As you enter appointments,
they are appended to the list, and "spos" is incremented. As you delete
appointments, "rpos" is incremented. Note that no deallocation occurs. Also,
there's no reuse of any sort. So delete() just looks like:
if((p=qretrieve())==NULL) return;
printf("%s\n", p);
where qretrieve() is a destructive removal of exactly the first item in the
list, never any other. And no deallocation occurs. (delete() could have
reasonably freed p after printing it.) The only change I see in 4th edition
is that it's been renamed to delete_ap(), and he's added a cast to malloc();
basically, he's made it more C++ friendly.
-s
error of the sort people make when not reviewing or checking code,
sure. *Approve*? I sure don't think so.)
gets(s);
if(*s==0) break; /* no entry */
p = malloc(strlen(s));
if(!p) {
printf("out of memory.\n");
return;
}
strcpy(p, s);
Code taken from p550 of CTCR, 2nd edition.
This one's actually fixed in the third edition! That's surprising, since
the 3rd edition seems to have fixed very few bugs.
On the other hand, the example is more fundamentally broken. The structure
of the "scheduler" is an array[MAX] of char *. As you enter appointments,
they are appended to the list, and "spos" is incremented. As you delete
appointments, "rpos" is incremented. Note that no deallocation occurs. Also,
there's no reuse of any sort. So delete() just looks like:
if((p=qretrieve())==NULL) return;
printf("%s\n", p);
where qretrieve() is a destructive removal of exactly the first item in the
list, never any other. And no deallocation occurs. (delete() could have
reasonably freed p after printing it.) The only change I see in 4th edition
is that it's been renamed to delete_ap(), and he's added a cast to malloc();
basically, he's made it more C++ friendly.
-s