M
miloody
Dear all:
I kept a buffer to handle the strings that output by snprintf and
tried to write a function to let the buffer works like a ring buffer.
That means the data will put at the head of buffer when buffer
overflow.
I think the prototype of SnPrintBuffer is correct but I have no idea
what should I pass to snprintf.
"snprintf (point, var1,fmt);" should be wrong.
If anyone knows the correct parameter to pass to snprintf, please let
me know.
Appreciate your help,
miloody
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
static unsigned int var1;
static unsigned int index2;
static char * point;
void SnPrintBuffer(const char *fmt, ...)
{
index2 = snprintf (point, var1,fmt);
var1 -= index2;
point += index2;
if(var1 < 2)
{ //handle overflow
}
}
int main(void)
{
point = malloc(4096);
var1 = 4096;
SnPrintBuffer("test 123 %d\n",__LINE__);
printf("%s",point);
}
I kept a buffer to handle the strings that output by snprintf and
tried to write a function to let the buffer works like a ring buffer.
That means the data will put at the head of buffer when buffer
overflow.
I think the prototype of SnPrintBuffer is correct but I have no idea
what should I pass to snprintf.
"snprintf (point, var1,fmt);" should be wrong.
If anyone knows the correct parameter to pass to snprintf, please let
me know.
Appreciate your help,
miloody
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
static unsigned int var1;
static unsigned int index2;
static char * point;
void SnPrintBuffer(const char *fmt, ...)
{
index2 = snprintf (point, var1,fmt);
var1 -= index2;
point += index2;
if(var1 < 2)
{ //handle overflow
}
}
int main(void)
{
point = malloc(4096);
var1 = 4096;
SnPrintBuffer("test 123 %d\n",__LINE__);
printf("%s",point);
}