?
=?ISO-8859-1?Q?Martin_J=F8rgensen?=
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
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