From: Christopher Croughton Message-Id: <97Dec12.145153gmt+0100.17026@internet01.amc.de> Subject: Re: strspn To: fighteer AT cs DOT com, djgpp AT delorie DOT com Date: Fri, 12 Dec 1997 13:48:36 +0100 Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk "John M. Aldrich" wrote: > Ian Chapman wrote: > > > > Hi, > > I tried to use the function strspn. I followed the example in libc.inf > > and I got a warning implict declaration of function from the compiler. > > The loader reported undefined ref. Is it in the libxxx.a? Are you using C++? Are you including string.h? If the answer to these is 'yes' and 'no' respoctively, then that's the problem. The string functions are all defined in string.h as C functions (i.e. with ordinary C external names rater than the C++ mangled names). If you don't include the header then the compiler will attempt to declare the function as int strspn(); which when compiled with C++ will result in a 'mangled' name which won't be found by the linker. > I just ran a test program and examined the docs, and strspn() works > fine. If you look closely at the example in the docs, there's a typo: > strspn is misspelled as "strcspn". Note that there are two functions. strspn returns the number of characters at the start of the first string matching those in the second, and strcspn returns the number not in the second. Or in other words, strspn returns the index of the first character not in the second string and strcspn returns the index of the first character in the second string. So: strspn ("abracadabra", "abc") == 2 strcspn("abracadabra", "cde") == 4 I hope (and believe) that the DJGPP library contains both, as per the ANSI spec. Chris C