I only make console programs, and would like to load my program like this ./programme.o -var1 value -var2 value_two

So how can I add some parameters, and that they're put in variables when the program loads?

10-07-2005

Daved

Those are command line arguments. You have to add the code to parse those arguments in your program. The first step is to change your main function to look like this:

Code:

int main(int argc, char* argv[])

The argc variable is the number of arguments. The argv variable is an array of C style strings holding each command line argument. The command line arguments are separated by spaces, unless they are in quotes. The first argument is always the program name. So for your example: ./programme.o -var1 value -var2 value_two argc would be 5 and the contents of argv would be:

You just have to find a way to look at that data and make sense of it.

10-07-2005

freak

Quote:

Originally Posted by Daved

Those are command line arguments. You have to add the code to parse those arguments in your program. The first step is to change your main function to look like this:

Code:

int main(int argc, char* argv[])

The argc variable is the number of arguments. The argv variable is an array of C style strings holding each command line argument. The command line arguments are separated by spaces, unless they are in quotes. The first argument is always the program name. So for your example: ./programme.o -var1 value -var2 value_two argc would be 5 and the contents of argv would be: