From: Nate Eldredge Newsgroups: comp.os.msdos.djgpp Subject: Re: indexOf function Date: 22 Nov 1999 14:08:17 -0800 Organization: InterWorld Communications Lines: 23 Message-ID: <8366yu18oe.fsf@mercury.st.hmc.edu> References: <81cafs$6m8 AT hermes DOT acs DOT unt DOT edu> NNTP-Posting-Host: mercury.st.hmc.edu X-Trace: nntp1.interworld.net 943308562 83752 134.173.45.219 (22 Nov 1999 22:09:22 GMT) X-Complaints-To: usenet AT nntp1 DOT interworld DOT net NNTP-Posting-Date: 22 Nov 1999 22:09:22 GMT X-Newsreader: Gnus v5.7/Emacs 20.4 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Morpheus" writes: > Could I use some pointer arithmetic to find the index once I use strstr? If > so, I'm not exactly sure how I'd do it. Could you demonstrate? Sure. Untested but probably correct code follows: ssize_t indexOf(const char *haystack, const char *needle) { const char *p; p = strstr(haystack, needle); if (p) return p - haystack; else return -1; } HTH -- Nate Eldredge neldredge AT hmc DOT edu