How to set parameters in command line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vutek0328
    New Member
    • Aug 2006
    • 1

    #1

    How to set parameters in command line

    I have a code of which I need to set parameters in order to run.

    I'm wondering how I can input the parameters through the command line.

    ./brownian 10 15 100 200

    with each number being a parameter for a certain variable in the code.

    I found this on the internet, but i'm not sure how that can help me.

    #include <stdio.h>

    int main(int argc, char *argv[])
    {
    int x;

    printf("%d\n",a rgc);
    for (x=1; x<argc; x++)
    printf(argv[x]);
    return 0;
    }
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You could try just compiling it and running it to see what it does.

    For the command line

    ./brownian 10 15 100 200

    in

    int main(int argc, char *argv[])
    {
    ...
    }

    then

    argc = 5

    argp[0] = "./brownian"
    argp[1] = "10"
    argp[2] = "15"
    argp[3] = "100"
    argp[0] = "200"

    allowing you to access the data from the command line

    Comment

    Working...