-1

I have a the following code in a for loop. I am trying to copy a string into a char**. However, when I run the below code, I never get to the "HERE" portion of my code. Instead, the next iteration of the for loop is executed. Can anyone explain this behavior?

string str = "ls -1";
string cmd = "ls";
char** command;

command = new char*[str.size()+1];

strncat(*command, str.c_str(), str.size+1); 
cout << "HERE\n";

*command = strtok(*command, " ");

execvp(cmd.c_str(), command);

EDIT:

I am using a char** to fit the parameters of execvp, and to use strtok to separate on spaces.

ThanksInAdvance
  • 497
  • 2
  • 7
  • 13

1 Answers1

0

too may pointers

char** command;
command = new char*[str.size()+1]

should be

char* command;
command = new char[str.size()+1]

Or better, stop mixing c++ string and c style 'strings'.

pm100
  • 48,078
  • 23
  • 82
  • 145