Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Application Security Testing: An Integral Part of DevOps

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.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date