开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜