943,946 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5923
  • C++ RSS
Sep 16th, 2004
0

Using command line parameters

Expand Post »
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)...

C++ Syntax (Toggle Plain Text)
  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...
Similar Threads
db0
Reputation Points: 10
Solved Threads: 0
Newbie Poster
db0 is offline Offline
3 posts
since Sep 2004
Sep 16th, 2004
0

Re: Using command line parameters

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
db0 is offline Offline
3 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Graphics In Pixel: Part II
Next Thread in C++ Forum Timeline: Polygon Program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC