Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C question

  • 29-11-2001 08:50PM
    #1
    Registered Users, Registered Users 2 Posts: 927 ✭✭✭


    ok, so i haven't used C in ages and as a result i'm a bit rusty.

    Basically i am generating psuedo-rando hex value and i want to pass them into a program 'findkey.exe'.

    Basically how can do i run the external programme ??


Comments

  • Registered Users, Registered Users 2 Posts: 347 ✭✭Static


    I think popen's your man. Open a pipe and fprintf to it.
    I think 8)


  • Closed Accounts Posts: 1 sphincter


    The easiest way, and it's fairly platform neutral would be
    to use system(), and pass the parameter on the command
    line. Copy/convert your number to a string, and:

    strcpy(command, "myotherprogramname ");
    strcat(command, myRandomNumberString);
    return = system(command);

    You can access parameters passed to your program via
    argc and argv, the implicit parameters of main(int argc, char **argv).

    An improvement on this would be to use one of the exec()
    variants - on a Unix platform, it'll cut down on the amount of
    processes that have to get created.

    Hope this helps.


  • Registered Users, Registered Users 2 Posts: 347 ✭✭Static


    Of course, be careful if "myRandomNumberString" is dynamically created by your program, you don't want to go exec'ing malicious input if you're not the one creating it. Check it. Also use strncat/strncpy.


  • Registered Users, Registered Users 2 Posts: 927 ✭✭✭decob


    Cheers, thanks Static/sphincter for the help.

    Static, yeah the numbers are being generated dynamically.


Advertisement