result of strstr(cs,ct) when ct is a null string
Erik Naggum
enag at ifi.uio.no
Tue May 21 09:13:35 AEST 1991
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 <string.h>
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>
--
Erik Naggum Professional Programmer +47-2-836-863
Naggum Software Electronic Text <enag at ifi.uio.no>
0118 OSLO, NORWAY Computer Communications <erik at naggum.uu.no>
More information about the Comp.lang.c
mailing list