unix - Handling command line flags in C/C++ -
i looking simple explanation/tutorial on flags are. understand flags work indicate command do. example:
rm -rf test
i know rm command remove test folder , -rf flags forcefulness command erase not folder files in it.
but, flags read/compiled??? handles flags? can i, example, write own c/c++ programme , designate different flags programme different things? hope asking right questions. if not, please allow me know.
this simple programme should demonstrate arguments passed programme (including programme name itself.)
parsing, interpreting , using arguments programmer (you), although there libraries available help.
int main(int argc, char* argv[]) { int i; for(i=0; i<argc; ++i) { printf("argument %d : %s\n", i, argv[i]); } homecoming 0; }
if compile programme a.out
, , run as:
prompt$> ./a.out paramone paramtwo -rf x.c
you should see output:
argument 0 : a.out argument 1 : paramone argument 2 : paramtwo argument 3 : -rf argument 4 : x.c
c unix command-line-arguments
No comments:
Post a Comment