Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Jun 29, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Command Line Arguments

I have a small console program that requires I pass arguments for it to run specific functions. I want to change the code so it automatically runs a set of command switches but cannot figure out how to do so. If I do
argv[0] = "-a -b -c" 
I get all kinds of errors.

I don't know what your code is doing but argv[0] should produce a valid string. The code snippet below iterates through the list of command line arguments. Perhaps you can use this as a starting point to get the information you need. Note that argv[0], the first argument, is always the name of the executable file.


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

   for (i = 0; i < argc; i++) {
      printf("Arg %d = %s\n", i, argv[i]);
   return 0;
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date