IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ticket #524: vsprintf-sample.c

File vsprintf-sample.c, 635 bytes (added by eugene, 21 years ago)

vsprintf discovery example

Line 
1
2/* send a message of arbitrary size, sending the size first */
3int Example (int device, char *format, ...) {
4
5 int Nbyte;
6 char tmp, *string;
7 va_list argp;
8
9 /* discover line length by setting output length to 0
10 MUST have a valid buffer even though it is not used */
11 va_start (argp, format);
12 Nbyte = vsnprintf (&tmp, 0, format, argp);
13 va_end (argp);
14
15 /* allocate space for the string + NULL end char */
16 ALLOCATE (string, char, Nbyte + 1);
17 memset (string, 0, Nbyte + 1);
18
19 /* need to restart varargs at this point */
20 va_start (argp, format);
21 vsnprintf (string, Nbyte + 1, format, argp);
22 va_end (argp);
23}