Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ike Naar <ike@sverige.freeshell.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: K&R2, exercise 5-4, strend(s,t) |
| Date | 2011-06-24 06:18 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrn3vfsj08b2b.ab5.ike@sverige.freeshell.org> (permalink) |
| References | <4e031bce$0$312$14726298@news.sunsite.dk> <itvds4$nr9$1@dont-email.me> <87oc1o875q.fsf@bazspaz.fatphil.org> <e4f82879-642f-4936-806c-f3a645897b76@m22g2000yqh.googlegroups.com> |
On 2011-06-24, Gene <gene.ressler@gmail.com> wrote:
> // UNCOMPILED; UNTESTED
> int strend(const char* str1, const char* str2)
> {
> int len2;
> char *p, *str2loc;
>
> if (str1 && str2) {
> len2 = strlen(str2);
> // p points to the unsearched part of str1
> p = str1;
> for (;;) {
> char *str2loc = strstr(p, str2);
> if (!str2loc)
> return 0;
> p = str2loc + len2;
> if (*p == '\0')
> return 1;
> }
> }
> return 0;
> }
You mentioned that the code is uncompiled and untested, and in
fact it has a few compilation errors but they are easy to fix.
One "real" problem: the for loop does not terminate if str2
is the empty string.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
K&R2, exercise 5-4, strend(s,t) arnuld <sunrise@invalid.address> - 2011-06-23 10:56 +0000
Re: K&R2, exercise 5-4, strend(s,t) Ian Collins <ian-news@hotmail.com> - 2011-06-23 23:03 +1200
Re: K&R2, exercise 5-4, strend(s,t) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-06-23 13:28 +0100
Re: K&R2, exercise 5-4, strend(s,t) Mark Bluemel <mark_bluemel@pobox.com> - 2011-06-23 14:08 +0100
Re: K&R2, exercise 5-4, strend(s,t) Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-06-24 02:22 +0300
Re: K&R2, exercise 5-4, strend(s,t) Gene <gene.ressler@gmail.com> - 2011-06-23 18:14 -0700
Re: K&R2, exercise 5-4, strend(s,t) Ike Naar <ike@sverige.freeshell.org> - 2011-06-24 06:18 +0000
Re: K&R2, exercise 5-4, strend(s,t) Ike Naar <ike@sverige.freeshell.org> - 2011-06-24 06:58 +0000
Re: K&R2, exercise 5-4, strend(s,t) Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-25 10:07 -0700
Re: K&R2, exercise 5-4, strend(s,t) arnuld <sunrise@invalid.address> - 2011-06-27 08:02 +0000
Re: K&R2, exercise 5-4, strend(s,t) Mark Bluemel <mark_bluemel@pobox.com> - 2011-06-27 10:13 +0100
Re: K&R2, exercise 5-4, strend(s,t) Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-27 11:54 -0700
Re: K&R2, exercise 5-4, strend(s,t) Mark Bluemel <mark_bluemel@pobox.com> - 2011-06-27 09:07 +0100
Re: K&R2, exercise 5-4, strend(s,t) Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-27 11:51 -0700
Re: K&R2, exercise 5-4, strend(s,t) Mark Bluemel <mark_bluemel@pobox.com> - 2011-06-28 08:19 +0100
Re: K&R2, exercise 5-4, strend(s,t) Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-28 16:03 -0700
csiph-web