Problems with printf()
Posted: Mon Oct 21, 2002 7:20 am
Hi,
at this time i write my own printf() function, here is the source, when i call the function with:
int var1 = 10;
printf("%i", var1);
the functions returns the wrong number, why ?
Here is the function:
int vsprintf(char *buf, const char *fmt, va_list args)
{
char * str;
int zeichen;
for (str=buf ; *fmt ; fmt++)
{
switch (*fmt)
{
case '%':
{
fmt++;
switch (*fmt)
{
case 'i':
{
// show me the var
zeichen = va_arg(args, int);
break;
}
}
break;
}
default:
{
// copy the char into the string
}
}
}
}
/* ************************************ */
int sprintf(char *buffer, const char *fmt, ...)
{
int i;
va_list args;
va_start(args, fmt);
i = vsprintf(buffer, fmt, args);
va_end(args);
return i;
}
the function should write 5 into the var
thanks, bye
at this time i write my own printf() function, here is the source, when i call the function with:
int var1 = 10;
printf("%i", var1);
the functions returns the wrong number, why ?
Here is the function:
int vsprintf(char *buf, const char *fmt, va_list args)
{
char * str;
int zeichen;
for (str=buf ; *fmt ; fmt++)
{
switch (*fmt)
{
case '%':
{
fmt++;
switch (*fmt)
{
case 'i':
{
// show me the var
zeichen = va_arg(args, int);
break;
}
}
break;
}
default:
{
// copy the char into the string
}
}
}
}
/* ************************************ */
int sprintf(char *buffer, const char *fmt, ...)
{
int i;
va_list args;
va_start(args, fmt);
i = vsprintf(buffer, fmt, args);
va_end(args);
return i;
}
the function should write 5 into the var
thanks, bye