home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
d
/
dec92.zip
/
1012076B
< prev
next >
Wrap
Text File
|
1992-10-13
|
682b
|
29 lines
/* strtokf.c: Collect tokens via a function */
#include <stdio.h>
#include <string.h>
static char *sp = NULL; /* Internal string position */
char *strtokf(char *s, int (*f)(char))
{
if (s != NULL)
sp = s; /* Remember string address */
if (sp == NULL)
return NULL; /* No string supplied */
/* Skip leading, unwanted characters */
while (*sp != '\0' && !f(*sp))
++sp;
s = sp; /* Token starts here */
/* Build token */
while (*sp != '\0' && f(*sp))
++sp;
if (*sp != '\0')
*sp++ = '\0'; /* Insert string terminator */
return strlen(s) ? s : NULL;
}