dwhitzzz

Override printf with parameter

Mar 13th, 2021 (edited)
1,353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. // for more info see see https://stackoverflow.com/a/34029868/5533075
  2.  
  3. #include <stdarg.h>
  4. const logging = 0;
  5. /**
  6.  *
  7.  * Help function in order to ovveride printf and enabling printf when needed
  8.  * // for more info see see https://stackoverflow.com/a/34029868/5533075
  9.  */
  10. void mylog(const char *pString, ...)
  11. {
  12.     if (logging == 0)
  13.     {
  14.         return;
  15.     }
  16.  
  17.     va_list args;
  18.     va_start(args, pString);
  19.     vprintf(pString, args);
  20.     va_end(args);
  21. }
  22.  
  23. //example
  24. mylog("print me!");
  25. int test = 2;
  26. mylog("test var %i", test);
Advertisement
Add Comment
Please, Sign In to add comment