🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Command line arguments
Hello,
I was wondering if any of you dos programmers out there could help me. I need to know how to pass command line arguments to my prog. I program in C++ and use DJGPP.
/-------\
|Foxtrot|
\-------/
All you have to do is add some parameters to your main() function. It should be like this
int main(int argc, char** argv)
Then, argc will contain the number of arguments (argument count), including the program name. That means argc will ALWAYS be at least 1. argv contains the strings (argument value), it''s an array of character arrays, or an array of strings. So if you ran your program like this:
program -param1 -param2 /param3
then argc would be 4, and
argv[0] == "-param1"
argv[1] == "-param2"
argv[2] == "/param3"
Hope this helps.
------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge
int main(int argc, char** argv)
Then, argc will contain the number of arguments (argument count), including the program name. That means argc will ALWAYS be at least 1. argv contains the strings (argument value), it''s an array of character arrays, or an array of strings. So if you ran your program like this:
program -param1 -param2 /param3
then argc would be 4, and
argv[0] == "-param1"
argv[1] == "-param2"
argv[2] == "/param3"
Hope this helps.
------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge
Yes, I''m sorry that was my typo ![](smile.gif)
It should be like this:
argc == 4
argv[0] == "program"
argv[1] == "-param1"
argv[2] == "-param2"
argv[3] == "/param3"
![](smile.gif)
It should be like this:
argc == 4
argv[0] == "program"
argv[1] == "-param1"
argv[2] == "-param2"
argv[3] == "/param3"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement