Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > execute command line arguments

Reply
Thread Tools

execute command line arguments

 
 
neha_chhatre@yahoo.co.in
Guest
Posts: n/a
 
      02-24-2008
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
 
Reply With Quote
 
 
 
 
Malcolm McLean
Guest
Posts: n/a
 
      02-24-2008

<> wrote in message
news:6a39150c-56c9-481c-afee-...
> 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

 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      02-24-2008
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.

 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      02-24-2008
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.
 
Reply With Quote
 
William Pursell
Guest
Posts: n/a
 
      02-24-2008
On Feb 24, 5:36 pm, neha_chha...@yahoo.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.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[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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RUN/execute a Command-Line command from an ASP page. Lucas Cowald ASP .Net 4 10-23-2003 11:09 AM
RUN/execute a Command-Line command from an ASP page Lucas Cowald ASP .Net Building Controls 1 10-22-2003 04:26 PM
RUN/execute a Command-Line command from an ASP page. Lucas Cowald ASP .Net Datagrid Control 1 10-22-2003 12:22 PM
RUN/execute a Command-Line command from an ASP page. Lucas Cowald ASP .Net Security 0 10-22-2003 11:15 AM
RUN/execute a Command-Line command from an ASP page. Lucas Cowald ASP .Net Mobile 0 10-22-2003 11:15 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57