Advertisement

Command line arguments

Started by January 26, 2000 11:12 PM
2 comments, last by tortxof 24 years, 10 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|-------/
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
Advertisement
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