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
Problems with printf()
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Problems with printf()
without a return in vsprintf, there is little chance you get a correct result !
Re:Problems with printf()
Hi,
no sorry, i have a easy function to write INT on the screen, with this function i write the var "zeichen" after zeichen = va_arg(args, int) on the screen, and the value is wrong. i know, later i write the value into the string, so i can use it for sprintf() and printf().
no sorry, i have a easy function to write INT on the screen, with this function i write the var "zeichen" after zeichen = va_arg(args, int) on the screen, and the value is wrong. i know, later i write the value into the string, so i can use it for sprintf() and printf().