Advertisement
hs202091

Writing a Custom printf() Wrapper Function in C

Nov 8th, 2018
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. Writing a Custom printf() Wrapper Function in C
  2.  
  3.  
  4. The function printf() and its cousins are among of the most versatile and well-known functions for sending formatted strings as output to files and the screen. They are implemented by many languages, including C, Java, Perl, PHP, Python, Ruby, and a handful of others.
  5.  
  6. One of printf()'s signature benefits is its ability to accept a variable number of arguments. This allows printed text to contain countless variations of formatted values and strings. In this tutorial, you will learn how to extend this functionality to create your own printf() wrapper function.
  7.  
  8. Why would we want to do this? One of the most obvious reasons would be to create our own warning() or error() functions that act just like printf() but can be conditionally switched on or off by, say, compiler or command line arguments. This would save us the need to wrap individual debug statements in conditional blocks, cutting down code size and complexity.
  9.  
  10.  
  11. Download the educational program from here:
  12. https://geistlink.com/bb6jJ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement