Path: utzoo!utgpu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!olivea!uunet!mcsun!news.funet.fi!fuug!funic!nntp.hut.fi!usenet From: Jari.Karjala@hut.fi Newsgroups: alt.hackers Subject: Re: Useful string function Message-ID: Date: 29 Jun 91 13:13:13 GMT References: <27187@ttidca.TTI.COM> Sender: usenet@nntp.hut.fi (Usenet pseudouser id) Organization: None Lines: 29 Approved: yes Nntp-Posting-Host: wonderwoman.hut.fi In article <27187@ttidca.TTI.COM> hollombe@ttidca.TTI.COM (The Polymath) writes: >(And to those who think they can improve on my code -- go for it. I make >no claim perfection). Here's a simple one I once translated from pascal, the original is in Sedgewick's good book "Algorithms" (which is nowadays even better when there is a version with C examples). (Add 'register' keywords into suitable positions if your compiler needs them.) --clip-- /* Returns pointer to string p in string a or NULL if not found */ char *strstr(a,p) char *a,*p; { char *c=p; while (*a && *p) if (*a++ != *p++) a -= p-c-1, p = c; if (*p) return NULL; else return a-(p-c); } --clip-- -- /*--- Jari.Karjala@hut.fi -- The World is Just a Huge Fractal ---*/ float O,I,o=0.075,h=1.5,T= -2,r,l;main(){int _=0,L=80,s=3200;for(;s %L|| (h-=o,T= -2),s;(4-(r=O*O)<(l=I*I)|++_==L)&&write(1,(--s%L?_