result of strstr(cs,ct) when ct is a null string

Doug Gwyn gwyn at smoke.brl.mil
Tue May 21 12:41:05 AEST 1991


In article <1991May20.163227.7166 at cfa.harvard.edu> todd at cfa.harvard.edu (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).

Of the handful of lines of text in the C standard describing strstr(),
almost an entire line is dedicated to answering exactly that question.
I would argue that it is also redundant, in that the main description
applies equally to the case of a zero-length string, but for some
reason people seem to get confused by zero-sized things.



More information about the Comp.lang.c mailing list