Re: K&R2, exercise 5.4
- From: arnuld <arnVuld@xxxxxxxxxxxxx>
- Date: Wed, 09 Apr 2008 17:30:39 +0500
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.
.
- Follow-Ups:
- Re: K&R2, exercise 5.4
- From: Barry Schwarz
- Re: K&R2, exercise 5.4
- From: Martin
- Re: K&R2, exercise 5.4
- From: arnuld
- Re: K&R2, exercise 5.4
- References:
- K&R2, exercise 5.4
- From: arnuld
- Re: K&R2, exercise 5.4
- From: Philip Potter
- K&R2, exercise 5.4
- Prev by Date: Re: Reading words from a text file
- Next by Date: Re: K&R2, exercise 5.4
- Previous by thread: Re: K&R2, exercise 5.4
- Next by thread: Re: K&R2, exercise 5.4
- Index(es):
Relevant Pages
|