("library strstr()". Grateful though I am that Google maintains
an archive of Usenet posts and makes it available, why oh why can't
they provide a posting interface without irritating glitches .... )
(Sigh) Incompetent programmers love "buffers" despite the fact that
"buffers" of ANY memory size are either bugs waiting to happen, or
memory hogs (there is no other alternative). People who take compsci
learn about links.
/* imagine that a large buffer is divided into five parts:
* 1 2 3 4 5
* test_strstr() copies the argument strings into slots 2 and 4, so
* that results can be compared for relative position, not just equality,
* because they're all in a single argument.
*/
void
test_strstr(char *haystack, char *needle) {
size_t needle_len, haystack_len;
char big_buffer[MAX_LEN * 5] = { 0 };
char *store_needle = big_buffer + (MAX_LEN * 1);
char *store_haystack = big_buffer + (MAX_LEN * 3);
char *lib_return, *my_return;
if (!needle || !haystack) {
fprintf(stderr, "error: test_strstr() needs valid strings.\n");
return;
}
needle_len = strlen(needle);
haystack_len = strlen(haystack);
if (needle_len > 128) {
This is a junior programmer script kiddie newbie error! You define
MAX_LEN above as 128 because da big boys do so, ignorantly copying,
aping their style.
Now this, I think, is a fair cop. Seebs, is this another case of
not getting the easy stuff right? though really, it's kind of hard
for me to imagine ....
News flash, Dweebach: the big boys do so SO THE SYMBOL CAN BE LATER
USED IN TESTS AND CAN BE CHANGED IN ONE PLACE. We knew this even in
mainframe Cobol.
But you've hard-coded the limit value!
How dare you, how dare you attack Schildt! Every fucking scrap of code
you've submitted to this newsgroup contains, not just bugs, but
completely wrong code which demonstrates that you come here to steal
intellectual product in the form of fixes to code that a professional
programmer would be ashamed of.
* A %s search which failed because you used strchr and not string.h's
strstr
Did it actually fail, in the context in which it was intended to be
used?
Search me. In the context such a tool is intended to be used, you
don't use C. Instead, you use a scripting language with builtin string
handling such as Rexx for the IBM mainframe, Visual Basic .Net or
Visual Basic for Applications on Microsoft platforms, or awk or its
descendants on Linux and unix. The code was completely useless to
anyone here as opposed to the instructional utility of demonstrating
how to learn string handling from people like Willem and Ben (and me)
by discarding string.h. It was a vanity effort which I think Peter
meant to show that he was qualified to code C. As such, he
demonstrated to me that he's far less qualified than he thinks he is,
and far less qualified than Heathfield, who has a good grasp of the
trees but sometimes gets lost in the forest. This has been confirmed
in recent weeks by each code snippet and program he has posted.
But...he would merit my silent pity, and I would make no comment, save
for the Schildt canard, and his treatment, last January, of my
collegial request for an exchange of email about Schildt. As you will
recall, he discarded my email unread and proceeded to repeatedly call
me (a fellow Apress author) "insane", a "moron", and a "kook". I am
none of these things.
The worst type of bug is one that doesn't "actually fail", most of the
time, or even never, when, years later, a maintenance programmer makes
a small change (such as adding %t as a different type of pattern, and
not expecting it to be changed), only to have the new code fail.
Professional programmers produce, as I produce, tokens of a type or
set of alternative texts which meet a range of neighboring
possibilities in such a way that it's easy to change from one token to
the next.
[Peter claims to have fixed the %s/%t confusion but his fix did not
address the ontological heart of the matter: that %s and %t are
strings, and IF you include string.h, THEN you need to use strstr.]
This sounds like the ravings of a "crazy man" who caught schizophrenia
from Nash only to uneducated paraprogrammers, whether the truly
unwashed, or people who "washed" out of other fields and came, filled
with self-hatred, shame and anger, to programming. But the fact is
that like a number of older programmers (such as Richard Stallman), I
spent a number of summers yearning for a CPU and drycoding programs,
along with learning mathematics, logic and the foundations of
mathematics. I also studied theater and literature in that time so
that by the time I was a graduate student in CS, I'd learned that
people and ideas matter far more than machines and software.
I'm afraid that Peter never had this chance, nor the chance to solve
difficult problems on his own, but not on his own terms. He was
sitting in a university, presumably with Mommy and Daddy paying his
tuition, unlike my middle class black and female students at DeVry,
who staggered in exhausted from working two jobs to pay their
tuition.
If he was interested in computers, it seems reasonable that he would
have taken a class; I jumped at the chance, in 1970, to take the first
class in computer science at Roosevelt University in Chicago. I can
only conclude that he's developed a passive-aggressive style which is
better treated by traditional psychiatry and outdoor service work than
medication...but would caution you, saying that that diagnosis is
probably irresponsible, possibly as irresponsible as people who
diagnose me as schizo because they can't read worth dick.
* A strlen with an off by one error
* switch() statements which use an unstructured and needlessly
misleading style
* Logic leaks in which you leave significant variables completely
uninitialized so that "the worst bug" can happen...everything seems to
work. But you give a ****, right?
And now this monstrosity.
Oh, this is going to be fun. I have to go to work at this time but I
look forward to a most amusing time with this code, Yet Another
Dweebach-o-rama.
128! MAX_LEN! 128! MAX_LEN!
[ snip ]