/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h> // for EXIT_SUCCESS
#include <stdarg.h> // for va_args()
#include <string.h> // for memset()
#define NDEBUG // disable assert
#include <assert.h>
// Constants
#define SOMESIZE 80
// Prototype
void append(char **pdest,size_t *max,char *fmt,...);
// Main
int main (int argc, char **argv)
{
(void)argc; // unused
(void)argv; // unused
char outputLineBuffer[SOMESIZE];
char *p = outputLineBuffer;
size_t max = sizeof(outputLineBuffer);
memset (&outputLineBuffer[0], 0x0, sizeof(outputLineBuffer));
// Test assert()
//append (NULL, NULL, NULL, 0);
unsigned int value1 = 42;
unsigned int value2 = 100;
float value3 = 42.42;
float value4 = 101.202;
printf ("outputLineBuffer: %s\n", outputLineBuffer);
append(&p,&max,"%u,",value1);
printf ("outputLineBuffer: %s\n", outputLineBuffer);
append(&p,&max,"%u,",value2);
printf ("outputLineBuffer: %s\n", outputLineBuffer);
append(&p,&max,"%.1f,",value3);
printf ("outputLineBuffer: %s\n", outputLineBuffer);
append(&p,&max,"%.1f,",value4);
printf ("outputLineBuffer: %s\n", outputLineBuffer);
return EXIT_SUCCESS;
}
// Functions
void append(char **pdest,size_t *max,char *fmt,...)
{
va_list ap;
int len;
assert(pdest != NULL);
assert(*pdest != NULL);
assert(max != NULL);
assert(fmt != NULL);
va_start(ap,fmt);
len = vsnprintf(*pdest,*max,fmt,ap);
va_end(ap);
(*pdest) += len;
(*max) -= len;
}