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

后端 未结 2 478
故里飘歌
故里飘歌 2020-12-10 09:58

Is it possible to put arguments in a systems call?

something like

system(\"rm %s %s\", string1, string2)
2条回答
  •  醉梦人生
    2020-12-10 10:19

    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);
    

提交回复
热议问题