I was sort of surprised there wasn't a function in C's libraries to deal with this..so I got to making it.
int strcnt(char cstr[], char cdlm[]) {
int oc=0;
for (strtok(cstr, cdlm); strtok(NULL, cdlm); oc++);
return oc;
}
This would be fine and well, but I need strtok() to work with the same string (ie, the string fed into the first arg in strcnt) elsewhere in the program, in another function. When I try to use strtok() in a different function with the same string, the second time I call it (to get the second token split off by the delimiter) it returns <null>. So I'm guessing I need to somehow "reset" strtok() at the end of strcnt(). Is this possible?