Re: K&R2, exercise 5.4



On Wed, 09 Apr 2008 12:59:32 +0100, Philip Potter wrote:

This is misleading. If you name a variable arrdiff, I expect it to
represent a difference. Here, I'd guess the difference between arrsize_s
and arrsize_t. But you instead store arrsize_s - arrsize_t - 1. Why?

I have removed this code. see down below.



The reason your strend() always returns 0 (or it does on my machine,
contrary to your complaint) is that the inner string-comparison loop
doesn't terminate when t or pj reach '\0' - so long as they equal each
other, the loop continues merrily along until it finds somewhere they
/don't/ equal. This means you skip right past the '\0' in t so by the
time you test for it, you've missed it. Even worse, you access beyond
the end of the array - which is undefined behaviour. Move the if test
into the loop.

that doe snot make the difference at all.


[Note that the worst case efficiency of O(n^2) requires fairly
pathological conditions, for example, s = "xxxxxxxxxxxxxxxxxxx" and t =
"xxxxxxxxxxxxxxxxA".]


right now, I don't care about efficiency. I wan the program to work. My
boss, who is standing above my head, keeps on saying, "you should resign
if you can't make such a simple C program in 2 days" :(



Philip

--
http://lispmachine.wordpress.com/

Please remove capital 'V's when you reply to me via e-mail.

.



Relevant Pages

  • Re: Where to find good lisp critiques?
    ... > His complaint about loop isn't about iteration vs recursion; ... > his critique, but it was a long time ago; I don't remember if he did ... but his complaint would not be complete unless he also included ... Loop, on the other hand, is rather ...
    (comp.lang.lisp)
  • Re: K&R2, exercise 5.4
    ... contrary to your complaint) is that the inner string-comparison loop ... the loop continues merrily along until it finds somewhere they ... the end of the array - which is undefined behaviour. ...
    (comp.lang.c)
  • Re: PCI bus numbering and orphaned devices
    ... > I'm thinking that the loop should be more like: ... My only complaint about this is that if no device is present in the ... the headertype check should be better bounded. ... To unsubscribe, ...
    (freebsd-current)
  • Re: Where to find good lisp critiques?
    ... rsobriquet@eudoramail.com (Rand Sobriquet) writes: ... but his complaint would not be complete unless he also included ... > Format is pretty straightforward. ... My mind slides over the loop body without gaining ...
    (comp.lang.lisp)
  • Re: std::map - erase+continue
    ... In the following code fragment: ... mylist.endpoints to the one-past-the-end element. ... go through the loop. ... Then you try to increment it, which is undefined behaviour. ...
    (comp.lang.cpp)