strtok function

Hello I am so sorry but learning to code on my own here.
If you can explain for me what happening here it would be great.
Things like what does two asterisk ** means and what does "new" means?

Thank you

#include <iostream>
#include <string>
#include <string.h>

using namespace std;

char** strtok(const char * str, char delim)
{
char **result = new char*[256];

const char* s;
int tokStart = 0;
int tokEnd = 0;
int tokenNo = 0;
int tokLen = 0;


// Implement your functionality to iterate through the
// string and copy tokens to the 'result'


return result;
}

int main()
{
string name;
cout << "Enter some text with ' '(space) as delimiter: \t";
getline (cin, name);
char** tokens = strtok(name.c_str(), ' ');
cout << "Tokenized string:\n";
int tokenNo = 0;
while(tokens[tokenNo] != '\0')
{
cout << tokens[tokenNo] << "\n";
tokenNo++;
}
}

The asterisk in this context means pointer. Two asterisks means pointer to pointer.

This

char **result = new char*[256];

means that enough memory is allocated to hold 256 pointers.
You might find the following tutorials helpful to explain pointers, and memory allocation:

http://www.cplusplus.com/doc/tutorial/pointers/

http://www.cplusplus.com/doc/tutorial/dynamic/
Topic archived. No new replies allowed.