Thread: How to disable printf ??

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    1

    How to disable printf ??

    i have a c code which uses some pre-compiled library calls, i just want to stop the printf calls inside that library only after certain point.

    Say like

    Code:
    void main(){
    //do some stuff
    
    printf("blah blah..");
    
    if(condn){
    LIB_call(); //don't print
    }else {
    LIB_call(); //Print
    }
    }
    Well if it was not a precompiled one i could have used

    #define printf if(condn){//}else{printf}

    which would comment out the unwanted printf's, but its a precompiled one
    It will be fine even if i can push the outputs to a separate file or something like that, i jus wanna separate them.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    printf writes to stdout which I believe can be treated as a standard file handle. So... you can try closing stdout with a call to fclose followed by a call to your pre-compiled library function and then reopen stdout after that (freopen) to re-enable output.

    Others may be able to provide more detail or clarifications if needed.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help again!!
    By ewic0190 in forum C Programming
    Replies: 1
    Last Post: 03-19-2010, 06:56 PM
  2. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 09:38 AM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  4. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 09:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM