Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > cpmmand line arguments

Reply
Thread Tools

cpmmand line arguments

 
 
neha_chhatre@yahoo.co.in
Guest
Posts: n/a
 
      02-24-2008
hello

tell me how to compile as well as run command line arguments.Also let
me know how to open a particular text file using command line asgument

say for example
if there are three text file pt1,pt2,pt3 and if i want to open pt1
please let me know as soon as possible
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      02-24-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) said:

> hello
>
> tell me how to compile as well as run command line arguments.Also let
> me know how to open a particular text file using command line asgument
>
> say for example
> if there are three text file pt1,pt2,pt3 and if i want to open pt1
> please let me know as soon as possible


This information is readily available from any good C tutorial book or
reference book. See, for example, "The C Programming Language", 2nd
edition, by Kernighan and Ritchie, or "C How to Program" (any edition), by
Deitel and Deitel, or "C: A Reference Manual" (any edition), by Harbison
and Steele. Look up "command-line arguments" in the index.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      02-24-2008
(E-Mail Removed) wrote:

> hello
>
> tell me how to compile as well as run command line arguments.


You cannot compile or run command line arguments. What you can do is
pass command line arguments to programs designed to accept them. In C
you do this by defining main as follows:

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

Obviously argc and argv can be any legal identifier but these two names
are practically universal for this purpose. Also argv could be written
as char **argv.

The general method is to first test argc. It could be zero or any
positive value. If it is non zero, then argv[0] to argv[argc-1] contain
the arguments, whatever they are. If argc is non-zero then argv[0] is
the program's invocation name, which may not be the same as the
executable file name of the program. argv[argc] is a null pointer.

> Also let me know how to open a particular text file using command line
> asgument


One simple example is:

int main(int argc, char **argv) {
FILE *fp;

if (argc > 1) {
fp = fopen(argv[1], "r");
if (fp == NULL) {
fprintf(stderr, "File: %s: open failed.\n", argv[1]);
exit(EXIT_FAILURE);
}
}
else {
fprintf(stderr, "Usage: program filename\n");
exit(EXIT_FAILURE);
}
/* ... */
}

> say for example
> if there are three text file pt1,pt2,pt3 and if i want to open pt1
> please let me know as soon as possible


Adapt from the above method.

PS. You have a habit of starting sentences as "tell me ..." etc., which
may strike some people as rude or arrogant. You might want to be a bit
more polite and do a bit more of your own homework. At least posting
whatever you have attempted so far is better than demanding answers.

 
Reply With Quote
 
dj3vande@csclub.uwaterloo.ca.invalid
Guest
Posts: n/a
 
      02-24-2008
In article <(E-Mail Removed)>,
Richard Heathfield <(E-Mail Removed)> wrote:

> See, for example, "The C Programming Language", 2nd
>edition, by Kernighan and Ritchie, or "C How to Program" (any edition), by
>Deitel and Deitel, or "C: A Reference Manual" (any edition), by Harbison
>and Steele.


Without having a copy to check, I'm pretty sure the first edition of
K&R will also answer the OP's question.
(Though there are of course other Very Good Reasons to prefer the
second.)


dave

--
Dave Vandervies dj3vande at eskimo dot com

Nothing is perfect. Not even Windows sucks perfectly.
-- Jay Maynard in the Scary Devil Monastery
 
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
Call again a variadic function (... variable number of arguments)with same arguments that its variadic wrapper moreau.steve@gmail.com C Programming 3 12-31-2008 07:13 AM
how to pass a function name and its arguments inside the arguments of other function? jmborr Python 1 11-03-2007 08:20 AM
function default arguments from other arguments tutmann C++ 4 10-17-2006 08:00 PM
function call with arguments which takes no arguments Neo C Programming 10 01-20-2005 06:31 AM
Difference between default arguments and keyword arguments Edward Diener Python 14 04-05-2004 11:26 PM



Advertisments