strwhich

Returns the specified substring.

Library:LibC
Classification:Other
Service:Characters and Strings

Syntax

  #include <string.h> 
   
  char *strwhich (
     char        *string,   
     int          which,
     const char  *source);
  

Parameters

string

(OUT) Points to the returned substring.

which

(IN) Specifies which substring to return. The numbering is zero-based, so use 0 to specify the first substring.

source

(IN) Points to a fully delimited character string.

Return Values

Returns the nth substring. Otherwise, returns a pointer to NULL.

Remarks

The source string must be correctly delimited by a character that does not otherwise occur in the string. The delimiter is assumed to be the first character of the source string. The strwhich function quits reading the string when it encounters a NULL character.

Multibyte strings are correctly supported as long as the delimiting character is single-byte and neither byte in any multibyte character in the source parameter happens to coincide with the delimiter.

You must allocated enough memory to hold the result.

The results of the following three calls are identical:

  char *s, string[32];
  
  s = strwhich(string, 3, "/dog/cat/chicken/mouse/")
  s = strwhich(string, 3, ".dog.cat.chicken.mouse.")
  s = strwhich(string, 3, "AdogAcatAchickenAmouseA")
  

Both s and the string parameter return mouse.

See Also