function

This is a discussion on function within the C Programming forums, part of the General Programming Boards category; How can i have a program execute a comand from inside the c program. I know that i have to ...

  1. #1
    Unregistered
    Guest

    function

    How can i have a program execute a comand from inside the c program. I know that i have to create a function?

  2. #2
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    Re: function

    Originally posted by Unregistered
    How can i have a program execute a comand from inside the c program. I know that i have to create a function?
    Be more specific man ...Okay u want to execute ur command prompt codes right ???
    if( that is what u want)

    system();/* this will help u out*/

    else
    printf ("???");

    E.g: wanna dir the files from ur c program

    system("dir"); /*Dirs the files*/
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  3. #3
    Unregistered
    Guest
    What is system()?? can't find documentation on it!!! and where and how do i use it?

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Unregistered guy,

    datainjector just got done saying you need to be more specific. You said you need to create a function. ok, that would have been my answer to the question of how do you execute a command in a program. so it is impossible to answer you unless you clarify what you are trying to do.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    There's a lot to be said for looking at the FAQ

    Also....

    Originally posted by FillYourBrain

    #define FLAME(user) cout << user << " must die!" << endl;

    FLAME("Troll_King")//for obvious reasons
    FLAME("Salem")//for Googling people to death
    Dont flame people just because they suggest you research your problem.

  6. #6
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    but it's not a REAL flame, just a fun flame macro!
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  7. #7
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I am willing to concede that Salem is not fully deserving of my FLAME macro. I suppose I can remove him soon. I was just in a mood that day and did not want to be googled. I'm better now
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by FillYourBrain
    I am willing to concede that Salem is not fully deserving of my FLAME macro. I suppose I can remove him soon. I was just in a mood that day and did not want to be googled. I'm better now
    And anyway.......use inline functions....not Macros

  9. #9
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I know but an inline function would have taken up more signature space. picky ol' snot

    be nice or I'll start using gotos
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >How can i have a program execute a comand from inside the c program. I know that i have to create a function?
    The system function is a standard way to do this, but it's behavior is system-dependent. It's simple enough to use without creating your own function, but if you must then you can do something like this:
    Code:
    int execCommand ( const char *command )
    {
      /*
      ** system returns an implementation-defined value.
      */
      return system ( command );
    }
    As stated in the code, the return value for system depends on your compiler, be careful how you handle those values because it will make your program non-portable if you aren't careful. Of course, you can simply ignore the return value.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21