c - Does strtok work with strings (as the delimiter)? -
for example:
friendly.
i don't "ly" @ end of word. can tokenize string "ly"
somecharvariable = strtok("friendly", "ly")?
the reply no. illustration of "ly" delimit on occurrence of either "l" or "y" or "yl" or "ly"
the delimiter parameter array of characters, each meant deed delimiter.
this illustration of asked for:
char *iterate(char *p, const char *d, const size_t len) { while(p!=null && *p && memcmp(p, d, len)==0) { memset(p, 0x0, len); p+=len; } homecoming p; } char ** tokenize( char **result, char *working, const char *src, const char *delim) { int i=0; char *p=null; size_t len=strlen(delim); strcpy(working, src); p=working; for(result[i]=null, p=iterate(p, delim, len); p!=null && *p; p=iterate(p, delim, len) ) { result[i++]=p; result[i]=null; p=strstr(p, delim); } homecoming result; }
c strtok
No comments:
Post a Comment