OT: CS education gone wrong (Was: Re: TDD is BS?)

"Jérôme M. Berger" jeberger at free.fr
Sat Jun 22 06:55:25 PDT 2013


Adam D. Ruppe wrote:
> On Friday, 21 June 2013 at 22:35:55 UTC, Andrei Alexandrescu 
> wrote:
>> Post it and I'll destroy it.
> 
> 
> inout(char)* mystrstr(inout(char)* haystack, const(char*) needle) 
> {
>      assert(haystack !is null);
> 
>      if(needle is null)
>          return haystack;
> 
>      const(char)* where = needle;
>      inout(char)* gotit;
> 
>      while(*haystack) {
>          if(*haystack == *where) {
>              if(gotit is null)
>                  gotit = haystack; // store where the match started
>              where++;
>              haystack++;
>              if(*where == 0)
>                  return gotit;
>          } else {
>              // if we were in the middle of a match, we'll want to
>              // check the current character again so only advance 
> if
>              // we're at the beginning
>              if(gotit is null)
>                  haystack++;
>              else {
>                  // partial match, but not complete so no good
>                  // start over, including the current *haystack
>                  where = needle;
>                  gotit = null;
>              }
>          }
>      }
> 
>      return null;
> }
> 
	I haven't tried running it, but this looks to me like it won't find
"ababc" in "abababc"...

		Jerome
-- 
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130622/e416172b/attachment.pgp>


More information about the Digitalmars-d mailing list