How to create a variable that is char *[] so it can be passed to a function

Multi tool use
Multi tool use


How to create a variable that is char * so it can be passed to a function



I'm trying to pass an argument to a function that takes a char * as input:


char *


int nArgs = 0;
CommandLineToArgvW(GetCommandLineW(), &nArgs);
const int commandLineArgsBufferSize = 500;
char commandLineArgs[commandLineArgsBufferSize];
wcstombs(commandLineArgs, GetCommandLineW(), commandLineArgsBufferSize);
int result = Catch::Session().run(nArgs, &commandLineArgs);



Here is the function prototype.


int Session::run( int argc, char* argv );



I am getting a compiler error:



C2664 'int Catch::Session::run(void)': cannot convert argument 2 from 'char (*)[500]' to 'char *'





You have created a pointer to a char array, you need an array of pointers to chars
– vu1p3n0x
Jul 2 at 19:38





Your function takes an array of char*, but you pass a pointer to an array of char
– Olivier Sohn
Jul 2 at 19:39


char*


char




1 Answer
1



The function is presumably intended to take the parameters of main() as arguments. So you want something like:


int main( int argc, char * argv ) {
int rv = Session::run( argc, argv );
}



If you wanted to construct the arguments yourself, something like:


void f() {
char * argv = {"foo", "bar" };
int rv = Session::run( 2, argv );
}





Would something like this work. const int commandLineArgsBufferSize = 2^10; char commandLineArgs[commandLineArgsBufferSize]; wcstombs(commandLineArgs, GetCommandLineW(), commandLineArgsBufferSize); char * commandLineArgsToPass = { commandLineArgs }; int result = Catch::Session().run(nArgs, commandLineArgsToPass);
– Donald Herman
Jul 2 at 23:07






@Donald Nope - that makes no sense. Do you know what the ^ operator does? You seem to be way over-thinking this.
– Neil Butterworth
Jul 2 at 23:13


^






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

r5sv4MiwB1PUM6fR A
DWTe5vNCVU81UIIgT4,ojpP7t0MTX5 ybAaEb1flWDRJtBvQ MT,ajg0lvM,rrT8seW,r3c3BzSGgoj5GJT r3N3raR sC7C ez27eyj

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications