This repository has been archived on 2024-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
CodeBlocksPortable/WATCOM/samples/clibexam/snprntf.c

16 lines
330 B
C

#include <stdio.h>
#include <stdlib.h>
/* Format output into a buffer after determining its size */
void main()
{
int bufsize;
char *buffer;
bufsize = snprintf( NULL, 0, "%3d %P", 42, 42 );
buffer = malloc( bufsize + 1 );
snprintf( buffer, bufsize + 1, "%3d %P", 42, 42 );
free( buffer );
}