1

i want to execute script cmd in the c program so the function SYSTEM(CONST CHAR ) does it but i want to use this function with 3 different parameters writing once . can anybody help me , is there any function of that kind.

2
  • I think you haven't understood the purpose of const parameters. const char * means that system doesn't overwrite its argument internally.
    – Fred Foo
    Nov 1, 2010 at 16:35
  • yes, i understood as it is CONST , but i want it not to be const but just a (char *) is there any function that supports this facility of taking input and functions as system() plz try to help me Nov 2, 2010 at 8:17

1 Answer 1

1

If I guessed it right you want to call a cmd using system() like function with multiple arguments, if yes then you can do following

char cmd[SIZE];
snprintf(cmd, <SIZE>, "<cmd> %d %f %c" argument1, argument2, argument3);
system(cmd);

also you can customize the snprintf to suite your needs and your arguments.

[EDIT] Used snprintf instead of sprintf [/EDIT]

2
  • @larsmans, I updated the recommendation for snprintf instead of sprintf. Happy now?
    – Himanshu
    Nov 1, 2010 at 16:36
  • but system() does not takes variable as parameter Nov 2, 2010 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.