execute command line arguments

Discussion in 'C Programming' started by neha_chhatre@yahoo.co.in, Feb 24, 2008.

  1. Guest

    please let me know

    if am using command line arguments, how to send arguments to a C
    program if i am working on ubuntu

    say for example
    suppose name of my program is prog.c
    if argc=3
    then how to send those three arguments(pt1.txt,pt2.txt,pt3.txt) to
    prog.c through command prompt if i am working on linux

    please reply urgently
     
    , Feb 24, 2008
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > please let me know
    >
    > if am using command line arguments, how to send arguments to a C
    > program if i am working on ubuntu
    >
    > say for example
    > suppose name of my program is prog.c
    > if argc=3
    > then how to send those three arguments(pt1.txt,pt2.txt,pt3.txt) to
    > prog.c through command prompt if i am working on linux
    >
    > please reply urgently
    >


    typer

    int main(int argc, char **argv)

    argc is the number arguments the user typed onm the commandline. Argv is an
    array of those arguments, this is to say argv[0] is the name of the program.
    argv[1] the first argument, argv[2] the second, and so forth.

    --
    Free games and programming goodies.
    http://www.personal.leeds.ac.uk/~bgy1mm
     
    Malcolm McLean, Feb 24, 2008
    #2
    1. Advertising

  3. santosh Guest

    wrote:

    > please let me know
    >
    > if am using command line arguments, how to send arguments to a C
    > program if i am working on ubuntu
    >
    > say for example
    > suppose name of my program is prog.c
    > if argc=3
    > then how to send those three arguments(pt1.txt,pt2.txt,pt3.txt) to
    > prog.c through command prompt if i am working on linux
    >
    > please reply urgently


    We are not your contract workers. We try to help but we cannot help you
    with your last minute problems.

    If your program executable is named 'prog', to give it the arguments
    pt1.txt, pt2.txt and pt3.txt do at the command prompt and with the
    programs's directory as your working directory:

    prog pt1.txt pt2.txt pt3.txt

    The general formula is:

    PROGRAME [ARG 1] [ARG 2] [...]

    You first type the program's name, as you would for any other program
    and then type out it's arguments one after the other, separated by a
    space. This will do fine for starting out. Later on you might like to
    write a general purpose arguments processor along the lines of getopt
    and others that handle more complicated formats and conditions.

    PS. Note that in the example above argc will be four, not three, as the
    program's invocation name also counts as a parameter, a difference from
    languages like Java.
     
    santosh, Feb 24, 2008
    #3
  4. wrote:
    >
    > say for example
    > suppose name of my program is prog.c
    > if argc=3
    > then how to send those three arguments(pt1.txt,pt2.txt,pt3.txt) to
    > prog.c through command prompt if i am working on linux


    This is a questoin about how to use the linux shell. You should ask in a
    linux group.
    However you can probably find out the answer very much quicker by
    examining any of the hundreds of shell scripts that will be on your
    linux box. Many of them will invoke programmes such as sed, grep, awk
    and so on with arguments.
     
    Mark McIntyre, Feb 24, 2008
    #4
  5. On Feb 24, 5:36 pm, wrote:

    > if am using command line arguments, how to send arguments to a C
    > program if i am working on ubuntu
    >
    > say for example
    > suppose name of my program is prog.c
    > if argc=3
    > then how to send those three arguments(pt1.txt,pt2.txt,pt3.txt) to
    > prog.c through command prompt if i am working on linux



    prog.c is an odd name for an executable, but if that's
    really what you have, you probably want to execute:

    $ ./prog.c pt1.txt pt2.txt pt3.txt

    This gives you argc == 4, argv[0] == "./prog.c",
    and argv == "pt$i.txt" for i in [1,2,3].

    If you really want argc == 3, you could try:

    $ ln -s prog.c pt1.txt && PATH=$PATH:. pt1.txt pt2.txt pt3.txt

    or something like that.
     
    William Pursell, Feb 24, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lucas Cowald
    Replies:
    4
    Views:
    1,074
    Tohid
    Oct 23, 2003
  2. Lucas Cowald

    RUN/execute a Command-Line command from an ASP page

    Lucas Cowald, Oct 22, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    248
    Genich
    Oct 22, 2003
  3. Lucas Cowald

    RUN/execute a Command-Line command from an ASP page.

    Lucas Cowald, Oct 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    212
    Oliver
    Oct 22, 2003
  4. Lucas Cowald

    RUN/execute a Command-Line command from an ASP page.

    Lucas Cowald, Oct 22, 2003, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    184
    Lucas Cowald
    Oct 22, 2003
  5. Lucas Cowald

    RUN/execute a Command-Line command from an ASP page.

    Lucas Cowald, Oct 22, 2003, in forum: ASP .Net Security
    Replies:
    0
    Views:
    240
    Lucas Cowald
    Oct 22, 2003
Loading...

Share This Page