Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with char ** argv

How do I assign a sequence of character strings to a char ** argv variable in a program? Its a command line argument. I'm currently trying to convert an .exe app to a dll.

For example:

{ "string1", "string2", "string3" } --- > char ** argv variable

My problem is somehow realted to this: How does an array of pointers to pointers work? but I can't get it to work using the snippet shown there. Help!

like image 719
Rock Avatar asked Mar 01 '26 08:03

Rock


1 Answers

const char* argv[] = {"string1", "string2", "string3", 0};

If the arguments aren't compile time constants I would do something like:

std::vector<const char*> arguments;
arguments.push_back(somePointer);
arguments.push_back(someOtherPointer);
arguments.push_back(0);
const char** argv = &arguments[0];

EDIT: Using PaxDiablos information that an argv-array should be null terminated.

like image 62
Andreas Brinck Avatar answered Mar 03 '26 20:03

Andreas Brinck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!