Re: need of a sprintf like function...
- From: Simon Biber <news@xxxxxxxxx>
- Date: Tue, 01 Nov 2005 01:26:40 +1100
Thad Smith wrote:
ypjofficial@xxxxxxxxxxxxxx wrote:
if there any library function which can avoid allocating memory to str. i.e i can write char * str = NULL; and directly pass str to that printf like function and the function will internally handle the allocation of memory and releasing it.
Yes. The C99 function snprintf has a length parameter, which you may set to 0.
Setting the length parameter of snprintf to zero does not actually accomplish the task of allocating memory. It just allows you determine what length the string should have. You can then allocate a block of memory of the correct length, and call snprintf again to actually perform the conversion to string. See my other post in this thread.
-- Simon. .
- References:
- Re: need of a sprintf like function...
- From: Thad Smith
- Re: need of a sprintf like function...
- Prev by Date: Re: Quick questions...
- Next by Date: Re: Why this code is working
- Previous by thread: Re: need of a sprintf like function...
- Next by thread: Re: Why this code is working
- Index(es):
Relevant Pages
|