How to pass command line arguments to a c program

前端 未结 4 1625
无人共我
无人共我 2020-12-05 11:02

I\'ve known how to write a program that accepts command line arguments ever since I learned to program. What I don\'t understand is how these parameters get their v

4条回答
  •  猫巷女王i
    2020-12-05 11:50

    On *nix, there's a very nice utility that lets you parse command-line flags and arguments in a very straightforward way. There's a nice example of its use on the same page.

    You would then run your program and pass arguments to it in a very standardised way:

    $ ./my_app -a -b -c argument1 argument2

    You can do without it and just parse them on your own but if you're aiming to make your app useful to other people it's definitely worth the effort of making it conforming.

提交回复
热议问题