Sep 21, 2017 at 9:30pm UTC
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++;
}
}
Sep 22, 2017 at 6:15am UTC
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.