I have written a piece of code to tokenise a string. It stores the tokens as an array of pointers. The array is allocated memory and each string is allocated memory using the new operator.
int b = 0;
//Create array of character pointers
token = new char *;
tokenptr = strtok(buffer, "#");
//Allocate memory for each string
buff = new char[strlen(tokenptr) + 1];
strcpy(buff,tokenptr);//copy tokenptr into buff
token[b] = tokenptr;
tokenptr = strtok(NULL, "#");
return token; //pointer to array
This generates the following error:
'return' : cannot convert from 'char ** ' to 'char *'
As i understand it, the code returns the address of the start of the array. Please can you advise how I can access the elements in this array from a function that calls Tokenise().
I have tried using:
char* tokenptr = Tokenise();
which points to the first element, but how do I access the other elements ?
Any help would be appreciated.