开发者

I want to pass all the arguments of the sprintf into ivlpp_main using argc and argv. code has same effect or not?

开发者 https://www.devze.com 2023-03-21 13:54 出处:网络
This one is Original. static void build_preprocess_command(int e_flag) { ivlpp_main(argc, argv); snprintf(tmp, sizeof tmp, \"%s%civlpp %s%s -F\\\"%s\\\" -f\\\"%s\\\" -p\\\"%s\\\" \",

This one is Original.

static void build_preprocess_command(int e_flag)

{

ivlpp_main(argc, argv);

snprintf(tmp, sizeof tmp, "%s%civlpp %s%s -F\"%s\" -f\"%s\" -p\"%s\" ",
       pbase, sep, verbose_flag?" -v":"",
       e_flag?"":" -L", defines_path, source_开发者_如何学运维path,
       compiled_defines_path);

}

This is my code

static void build_preprocess_command_and_run(int e_flag) {

char **myargv;

int argc, arg;

myargc = 7;

myargv = new char(myargc);

arg = 0;

myargv[arg] = new char (strlen(pbase) + strlen("ivlpp") + strlen(sep) + 2);

       sprintf(argv[arg], strlen(pbase) + 2,"s%s%ccivlpp", pbase, sep);

myargv[arg++] = new char (strlen(defines_path) + strlen("-F\”%s\”"));

myargv[arg++] = new char (strlen(defines_path) + strlen("-f\”%s\”"));

myargv[arg++] = new char (strlen(defines_path) + strlen("-f\”%s\”"));

myargv[arg++] = new char (strlen("-p\”%s\”"));

myargv[arg++] = new char (strlen("-v"));

myargv[arg++] = new char (strlen("-L"));

if (verbose_flag) {

 //argv[arg++] = "-v";

 sprintf("-v");

}

if (!e_flag) {

 //argv[arg++] = "-L";

 sprintf("-L");

}

snprintf( "-F\"%s\"", defines_path);

snprintf( "-f\"%s\"", source_path);

snprintf( "-f\"%s\"", compiled_defines_path);

ivlpp_main(argc, argv);

}


No. First code is wrong. Second doesn't compile. sprintf has more arguments than the single one you're using. my code on your last question works (this is like a duplicate).

0

精彩评论

暂无评论...
验证码 换一张
取 消