Advertisement
a3f

counting printfs

a3f
May 8th, 2014
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. // is undefined behaviour, works on gcc
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4.  
  5. int printf_count = 0;
  6. int printf(const char *fmt, ...)
  7. {
  8. printf_count++;
  9.  
  10. va_list va;
  11. va_start(va, fmt);
  12. int ret = vprintf(fmt, va);
  13. va_end(va);
  14.  
  15. return ret;
  16. }
  17. int main (void)
  18. {
  19.     printf("TEST\n");
  20.     printf("TEST\n");
  21.     printf("TEST\n");
  22.  
  23.     printf("%d printf's were called", printf_count);
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement