programming.nbk: Home | Index | Next Page: DDE | Previous Page: Code: string auto array
//############################################################################## // parse the given string into tokens // strings within single quotes (') are considered a single token // if called with string == NULL, it starts where it left off last call //############################################################################## char *mystrtok(char *string, char *delimiters) { static char *work; char *start; int in_quotes; if (string != NULL) work = string; in_quotes = 0; if (!(*work)) return (NULL); start = work; /* move forward looking for the next character in delimiters */ while (*work) { if (strchr(delimiters, *work) && !in_quotes) break; if (*work == 0x27) in_quotes = in_quotes ? 0 : 1; work++; }; // replace the delimiter with '\0' to signal end of the string if (*work) { *work = '\0'; work++; } return (start); }
programming.nbk: Home | Index | Next Page: DDE | Previous Page: Code: string auto array
Notebook exported on Monday, 7 July 2008, 18:56:06 PM Eastern Daylight Time