5 ms·
I'll change your mind: If you pass NULL as the destination pointer, it doesn't write any string. If you combine this with %n at the end of the format string, y
by bruce343434 3mo ago
I'll change your mind:
If you pass NULL as the destination pointer, it doesn't write any string. If you combine this with %n at the end of the format string, you can get the exact length that the output string would be. Then you allocate that, then you print again, into the actual destination buffer this time.
- baq 3mo agoIf anything I just got entrenched in my opinion. The second best option, maybe, would be to not accept any destination pointers and have the default and only possible behavior just like what you describe.
- bruce343434 3mo agoI agree. I tend to use the gnu "asprintf" which simply returns a properly allocated char buffer with the formatted string in it. And on platforms that don't feature asprintf (windows) you can build your own using sprintf!