token to a multidimensinal array


How do you tokenize a string and put it in a mulitdimensional array, letter by letter? Im getting the following error "invalid conversion from char*' tochar".
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void tokens( char *sptr)
{
	int i;
	char *p, tokens[100][16];
	
	while (p != NULL)
	{
		for ( i = 0; i <= 100; i++)
		{
			for (int j = 0; j <= 16; j++)
			{
			    p = strtok (sptr, " ,.-");

		    	tokens[i][j] = p;
			 
			}
		}
	}
}
Firstly, you're not using strtok right. You should only pass it sptr the first time. See the example in http://www.cplusplus.com/reference/clibrary/cstring/strtok/
Secondly, you have too many loops. The description of the algorithm is "while strtok finds a token, copy that token into an array". This implies two loops - one for calling strtok and another for copying. I suggest that you let strcpy take care of copying though.
Topic archived. No new replies allowed.