Get the latest tech news
How to Use Snprintf
The sprintf family of functions (sprintf, snprintf, vsnprintf, …) have this little-known feature to what size your buffer should be. In cases where you don’t have a fixed upper bound, this is really useful.
In cases where you don’t have a fixed upper bound, this is really useful. The functions snprintf() and vsnprintf() write at most size bytes (including the terminating null byte (‘\0’)) to str. Go forth and please stop manually computing buffer sizes.
Or read this on Hacker News