Name

strsep - extract token from string

Library

libc.lib

Synopsis

  #include <string.h>
  char * strsep (char **stringp, const char *delim);

Return values

strsep function returns a pointer to the token, i.e it returns the original value of *stringp


Detailed description

The strsep function locates, in the string referenced by *stringp, the first occurrence of any character in the string delim (or the terminating \0’ character) and replaces it with a \0’. The location of the next character after the delimiter character (or NULL, if the end of the string was reached) is stored in *stringp. The original value of *stringp is returned.

An "empty" field (i.e., a character in the string delim occurs as the first character of *stringp) can be detected by comparing the location referenced by the returned pointer to \0’.

If *stringp is initially NULL, strsep returns NULL.


Examples

#include <string.h>
#include <stdio.h>
int main()
{
    char *one=(char *)malloc(12);
    char *res;
    char **two=&one;
    strcpy(one,"Hello,World");
    res=strsep(two,",");
    if(strcmp(res,"hello"))
    printf("%s\n",res);      
    return 0;
}

         

Output

Hello

         

See also

memchr, strchr, strcspn, strpbrk, strspn, strstr, strtok

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top