i have made a dynamic string implementation that i use on most of my projects. one thing that has been bothering for quite some time now is how to add standard c formatting to it, that is equivalents of functions like sprintf() and relatives. i could just wrap snprintf(), but than there is a possibility of truncating the string if there is not enough space. i have also seen an approach of first calling snprintf() with NULL as dest and based on the return allocating enough space and calling it again, but that does not seem that optimal. there are also gnu extension functions that can do something similar, but allocate its own buffers, which i would than have to copy, which is also not ideal. of course there is an option or writing it by hand, or some reasonable subset of it, but i am looking for a way to avoid that if possible.
ideally, i would like to have init function that has a sprintf() like signature but makes sure to allocate enough space, and also appendf() that appends specified formatter to a string. any tips?
[link] [comments]


![[macOS] [Mac App Store - Game deals post #4 - DEATH STRANDING DIRECTOR'S CUT, Cyberpunk 2077: Ultimate, Frostpunk 2, The Medium, DREDGE and more at discounted prices.]](https://www.browardlocals.com/hello.gif)
![[iOS][Mac] Lifetime Pro IAP $10 → Free (48h) — RecordMark — voice notes with pins & transcription](https://external-preview.redd.it/YtBQSbs6xMBS__OIrr9eC4Ek71sFJIkh4c0So1yZWNc.png?width=640&crop=smart&auto=webp&s=0744d122255bc144037a76e5c4f087b72aa1cd1b)
![The Alabama Solution Trailer (2025) [1:57:00]](https://external-preview.redd.it/Djo00T_SWKRom0I3g_WiEUUbwfq9p7SdtGkTs_4kTak.jpeg?width=320&crop=smart&auto=webp&s=6cbbaea250ec8dd60e8a8db9f8e82ab1147b0172)


English (US) ·