Returns the specified substring.
#include <string.h> char *strwhich ( char *string, int which, const char *source);
(OUT) Points to the returned substring.
(IN) Specifies which substring to return. The numbering is zero-based, so use 0 to specify the first substring.
(IN) Points to a fully delimited character string.
Returns the nth substring. Otherwise, returns a pointer to NULL.
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.