954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Using command line parameters

Hi all. Somthing strange is going on... I want to use "-debug" command line parameter to make my app show some debug info. Here is my code (not entire but needed part)...

#include <iostream.h>

bool debug_mode=0;

int main(int argc, char **argv)
{

if(argv>1) cout << argv[0] << endl << argv[1] << endl;

if( (argc>1) && (argv[1]=="-debug") ) debug_mode=1;

// Some code that checks my database integrity, and does not use
// debug_mode variable in any way

if(debug_mode)
{
  cout << "Some debug information" << endl;
}

// here is additional code

return 0;

}


The problem is that when I start my app with "-debug" (exactly "./dbreader -debug") parameter I can see that my argv[0] is "./dbreader" and argv[1] is exactly "-debug" but my IF STATMENT didn't set debug_mode to "1", and so no additional info is shown...

db0
Newbie Poster
3 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

I have already solved my problem... I had to use "strcmp" function instead of "==" operator to compare argv[1] with "-debug" string....
I think i have to sleep a little more than 3-4 hours to make my brains work better :) ...

db0
Newbie Poster
3 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You