how to write a program that takes arguments from commandline?
- From: Martin Jørgensen <unoder.spam@xxxxxxxxxxxx>
- Date: Sat, 11 Feb 2006 19:48:19 +0100
Hi,
I'm learning C-programming. I have a program which I would like to modify so it takes arguments from the commandline. Let call the program: program.exe.
Could somebody shortly explain how I get this behaviour:
C:>program -help or C:>program -h
printf("\nBla. bla. Here is some help and arguments\n").... etc.
C:>program -dt=0.1 -tend=10 (etc. additional switches might be added).
In the program:
float (or double) dt should become 0.1. The integer variable named "tend" should be assigned respectively to 10.
In case of any problems such as for instance C:>program dt=adg, the program should respond with something like "dt: Invalid syntax. Exiting.".
I suspect that one should change the program such that "int main(?? something goes in here, right?)" instead of int main(void), but I'm not really sure of how to address this problem. If somebody has any sample code in C to post, I would be very happy.
Thanks in advance for any hints...
Med venlig hilsen / Best regards
Martin Jørgensen
--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
.
- Follow-Ups:
- Re: how to write a program that takes arguments from commandline?
- From: tmp123
- Re: how to write a program that takes arguments from commandline?
- From: pete
- Re: how to write a program that takes arguments from commandline?
- From: stathis gotsis
- Re: how to write a program that takes arguments from commandline?
- From: Alvin
- Re: how to write a program that takes arguments from commandline?
- From: Walter Roberson
- Re: how to write a program that takes arguments from commandline?
- Prev by Date: Re: How do I convert an int to binary form?
- Next by Date: www.bornwitit.com
- Previous by thread: size_t and C90/C99
- Next by thread: Re: how to write a program that takes arguments from commandline?
- Index(es):
Relevant Pages
|