Re: how to write a program that takes arguments from commandline?
- From: "stathis gotsis" <stathisgotsis@xxxxxxxxxxx>
- Date: Sat, 11 Feb 2006 21:28:32 +0200
"Martin Jørgensen" <unoder.spam@xxxxxxxxxxxx> wrote in message
news:j4o1c3-c29.ln1@xxxxxxxxxxxxxx
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...
Maybe this is relevant:
http://c-faq.com/misc/argv.html
.
- Follow-Ups:
- Re: how to write a program that takes arguments from commandline?
- From: Martin Jørgensen
- Re: how to write a program that takes arguments from commandline?
- References:
- how to write a program that takes arguments from commandline?
- From: Martin Jørgensen
- how to write a program that takes arguments from commandline?
- Prev by Date: Re: how to write a program that takes arguments from commandline?
- Next by Date: Re: size_t and C90/C99
- Previous by thread: Re: how to write a program that takes arguments from commandline?
- Next by thread: Re: how to write a program that takes arguments from commandline?
- Index(es):
Relevant Pages
|