开发者

C: Anyway to load parameters into a system() call

开发者 https://www.devze.com 2023-02-20 21:58 出处:网络
Is it possible to put arguments in a s开发者_开发问答ystems call? something like system(\"rm %s %s\", string1, string2)

Is it possible to put arguments in a s开发者_开发问答ystems call?

something like

system("rm %s %s", string1, string2)


The prototype for the system function is:

int system(const char *command);

so, no. But, how about:

snprintf(buffer, sizeof(buffer), "rm %s %s", target1, target2);
system(buffer);


Try this:

private:    
char command[128];
char temp[10] = {'"','I','P','v','4','"'}; //snprintf();
public:
int SysInfo(){
    snprintf(command,sizeof(command), "ipconfig | find  %s > save.log",temp);
    system(command);
}
0

精彩评论

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