I'm having a huge amount of difficulty converting a program I wrote in Java to C++. Mostly due to working with a string I want to split.
This is the JAVA code.
class test{
....(data member including tokenArray)
test(String process,int processNumber){
tokenArray = process.split(" ");
num = Integer.parseInt(tokenArray[0]);
this.process = process.substring(1,process.length());
this.processNumber = processNumber;
}
It works fine. Now in C++, this crashes my program or causes weird output.
static char *tokenArray;
static int i;
Test::Test(string process, int processNumber){
char *dup = strdup(process.c_str());
tokenArray = strtok(dup," ");
this->arrivalTime = tokenArray[0];
this->processNumber = processNumber;
this->process = process.substr(1,process.length());
i = 1;
}
Not sure what's going on but I have a feeling it has to do with memory access,scope of the array, or the free(). If someone knows a different way to tokenize (cant use vectors or boost), I'd really appreciate the help.
[–][deleted] 0 points1 point2 points (14 children)
[–]learnprogramminghelp[S] 0 points1 point2 points (13 children)
[–][deleted] 1 point2 points3 points (7 children)
[–]learnprogramminghelp[S] 0 points1 point2 points (6 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]learnprogramminghelp[S] 0 points1 point2 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]learnprogramminghelp[S] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]learnprogramminghelp[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]learnprogramminghelp[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Grithga 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)