Richard is on the right track. I use a function to do this kind of thing that wraps strtok in a loop and saves a pointer to each token found in an array. It is not perfect for dealing with CSV files because it does not handle commas embedded in a quoted string correctly. Here's what it looks like :
int ParseTokens( char * buffer, const char * delims, char * tokens[], int maxTokens )
{
char * cptr = nullptr;
char * pbuffer = buffer;
int tokenCount = 0;
int x;
for( x = 0; x < maxTokens; x += 1 )
{
cptr = strtok( pbuffer, delims );
if( ! cptr )
break;
tokens[ tokenCount ] = cptr;
++tokenCount;
pbuffer = nullptr;
}
return tokenCount;
}
To call it you can do this :
#define MAX_TOKENS 16
char * tokens[ MAX_TOKENS ] = { nullptr };
const char * delimiters = ",";
int tokenCount = ParseTokens( string, delimiters, tokens, MAX_TOKENS );