execute command line arguments

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • neha_chhatre@yahoo.co.in

    execute command line arguments

    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.t xt,pt2.txt,pt3. txt) to
    prog.c through command prompt if i am working on linux

    please reply urgently
  • Malcolm McLean

    #2
    Re: execute command line arguments


    <neha_chhatre@y ahoo.co.inwrote in message
    news:6a39150c-56c9-481c-afee-1a75cc475d12@e2 5g2000prg.googl egroups.com...
    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.t xt,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.


    Comment

    • santosh

      #3
      Re: execute command line arguments

      neha_chhatre@ya hoo.co.in 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.t xt,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.

      Comment

      • Mark McIntyre

        #4
        Re: execute command line arguments

        neha_chhatre@ya hoo.co.in wrote:
        >
        say for example
        suppose name of my program is prog.c
        if argc=3
        then how to send those three arguments(pt1.t xt,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.

        Comment

        • William Pursell

          #5
          Re: execute command line arguments

          On Feb 24, 5:36 pm, neha_chha...@ya hoo.co.in 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.t xt,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[i] == "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.

          Comment

          Working...