execute command line arguments

N

neha_chhatre

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
 
M

Malcolm McLean

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.
 
S

santosh

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.
 
M

Mark McIntyre

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.
 
W

William Pursell

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top