Thread: print to console or /dev/null for debugging info

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    72

    print to console or /dev/null for debugging info

    Hi All

    I need a solution for my debug functionallity. Depending on the variable DEBUG, messages should or shouldn't appear in the console.

    Can this be done with fprintf ? If DEBUG is 0 it should point to /dev/null and if 1 to the console (if it exists) ?

    Any suggestions ?

    thnx in advance
    Luca

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    #ifdef DEBUG
    #define fdebug stdout
    #else
    #define fdebug stderr
    #endif
    
    ...
    
    fprintf( fdebug, ... );
    Something like that?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    23
    Or perhaps something like this?

    Code:
    FILE* debug;
    
    if (DEBUG)
       debug = fopen("/dev/null", "w");
    else
       debug = stderr; /* or stdout */
    
    fprintf(debug, "Debug Information");
    Last edited by hawaiian robots; 04-21-2010 at 01:43 AM.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    72
    thnx a lot!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with a simple console game
    By DZeek in forum C++ Programming
    Replies: 9
    Last Post: 03-06-2005, 02:02 PM
  2. Help doing an e-mail program in c...
    By Tyler_Durden in forum C Programming
    Replies: 88
    Last Post: 01-02-2005, 03:12 PM
  3. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM
  4. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM
  5. Replies: 3
    Last Post: 12-06-2001, 05:30 AM