🎉 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

Started by
2 comments, last by tortxof 24 years, 5 months ago
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| \-------/
/-------|Foxtrot|-------/
Advertisement
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
I think:

argv[0] should be the program fullpath
argv[1] should be "-param1"
... and so forth.
"after many years of singularity, i'm still searching on the event horizon"
Yes, I''m sorry that was my typo
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