#1
  1. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69

    passing variable arguments to system()


    Hi all, I'm a bit of a noob when it comes to C++ so sorry if this sounds a lil dumb ;)..

    Anyway what I'm trying to do is use the system() function to execute different versions of a program stored on a CD, inside folders named for the version number i.e 1. The program needs to prompt the urser for the version number then create a path I can use in system().

    I tired simply getting the path from cin and passing it to system() but it doesn't like it at all. It keeps saying "invalid initializer". can system take variable arguments? if not i guess i'll just use an if statment :)

    Thanks in advance guys :).

    Mark.
  2. #2
  3. No Profile Picture
    status unknown
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    262
    Rep Power
    12
    Can you show us how you're trying to use it?
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247

    Re: passing variable arguments to system()


    Originally posted by netytan
    can system take variable arguments? if not i guess i'll just use an if statment :)
    No, but you can use sprintf() to build a command string and pass that to system()
    Code:
       char cmd[1024];
       sprintf(cmd, "progname %s %s", arg1, arg2);
       system(cmd);
    Alternatively, you can also use the exec..() family of functions.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Thanks for the quick responce guys, :) i'll give it ago now!

    Mark.
    Last edited by netytan; August 30th, 2003 at 03:12 PM.
  8. #5
  9. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    Try this:
    system(v.c_str());
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Thank's scorp, I tried the first and it didn't work.. but, the second one works a treat! :)

    Thanks again,
    Mark.

IMN logo majestic logo threadwatch logo seochat tools logo