/* nextok.c Mark W. Renton, MACROSTAFF, renton@pmel.noaa.gov, May 1995 "nextok" is exactly like strtok, except that it allows empty values. example: ",2,,4," delimited by "," has 5 values (there are 4 commas), of which the 1st, 3rd, and 5th are zero-length non-NULL strings. */ #include #include char *nextok(s,delim) char *s, *delim; { char *token; static char *last, *end; if ( s!=NULL ) { end = s + strlen(s) + 1; } else { if ( (s=last)==NULL ) return NULL; } if ( s==end ) { last=NULL; return NULL; } ; token = s; s += strcspn(s,","); *s++ = '\0' ; last = s; return token; }