Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!ugle.unit.no!nuug!ifi!enag From: enag@ifi.uio.no (Erik Naggum) Newsgroups: comp.lang.c Subject: Re: result of strstr(cs,ct) when ct is a null string Message-ID: Date: 20 May 91 23:13:35 GMT References: <1991May20.163227.7166@cfa.harvard.edu> Sender: enag@ifi.uio.no (Erik Naggum) Organization: Naggum Software, Oslo, Norway Lines: 35 In-Reply-To: todd@cfa.harvard.edu's message of 20 May 91 16: 32:27 GMT Todd Karakashian writes: | | Is the result of strstr(cs,ct) defined when ct is a null string | (i.e., when *ct == '\0')? | | SunOS 4.1.1 strstr() returns cs in this situation. I checked the man | page, K&R 2, and the ANSI standard but couldn't find any illuminating | information (like, for example, saying it was undefined). | | I am thinking perhaps that strstr() ought to return NULL in this case, or | maybe a pointer to the null termination of cs, but I am curious what | other people think. The null string matches any string, including the null string. 4.11.5.7 in dpANS C of 1/11/88 (which is the one I have handy -- time to drag the ANSI standard with me in addition to so many other bulky standards, it seems) clearly states: #include char *strstr (const char *s1, const char *s2); ... Returns The strstr function returns a pointer to the located string, or a null pointer if the string is not found. If s2 points to a string with zero length, the function returns s1. -- Erik Naggum Professional Programmer +47-2-836-863 Naggum Software Electronic Text 0118 OSLO, NORWAY Computer Communications