Using command line parameters

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2004
Posts: 3
Reputation: db0 is an unknown quantity at this point 
Solved Threads: 0
db0 db0 is offline Offline
Newbie Poster

Using command line parameters

 
0
  #1
Sep 16th, 2004
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)...

  1. #include <iostream.h>
  2.  
  3. bool debug_mode=0;
  4.  
  5. int main(int argc, char **argv)
  6. {
  7.  
  8. if(argv>1) cout << argv[0] << endl << argv[1] << endl;
  9.  
  10. if( (argc>1) && (argv[1]=="-debug") ) debug_mode=1;
  11.  
  12. // Some code that checks my database integrity, and does not use
  13. // debug_mode variable in any way
  14.  
  15. if(debug_mode)
  16. {
  17. cout << "Some debug information" << endl;
  18. }
  19.  
  20. // here is additional code
  21.  
  22. return 0;
  23.  
  24. }

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...
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 3
Reputation: db0 is an unknown quantity at this point 
Solved Threads: 0
db0 db0 is offline Offline
Newbie Poster

Re: Using command line parameters

 
0
  #2
Sep 16th, 2004
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 ...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC