problem in passing varable number argument to another functi
Posted: Sun Jan 15, 2006 1:21 pm
hello every one
this is my first time to ask in this great forum....
so.... in brief
I'm writing an OS "unix clone" ,and i started with the print functions....
the main two parts in this function is :tk_printf and tk_sprintf
the two function prototype:
1-int tk_printf(const char*, ...);
printf() calls sprintf() to format the pre-formatted string containing unlimited arguments then prints the ouptput of sprintf() on the standard output. returns the number of characters printed on the standard output not including the trailing '\0' used to end output to strings or a negative value if an output error occurs.
2-int tk_sprintf(char*,const char*, ...);
sprintf() formats the pre-formatted string containing unlimited arguments and prints it in a buffer. the 1st parameter is a pointer to the buffer which will contain the formatted string, the 2nd parameter is a pointer to a constant string containing the pre-formatted string, the remaining parameters is the list of arguments as passed in the pre-formatted string.the pre-formatted string uses the same format specifies as the libc printf() function.
i'm using the va_list in the sprintf function to deal with the arguments...
the problem is that when i pass the string from the tk_printf to the tk_sprintf function the va_list in the sprintf can't locate the arguments.
the code of tk_printf function:
int tk_printf(const char* nformatted,...)
{
char buffer[256];
int index=0,num_printed,check,char_num=0,nf_index=0;
num_printed=tk_sprintf(buffer,nformatted);
for(index=0,check=0;num_printed>index;index++,check++)
{
putchar(buffer[index]); /*using the putchar of libc until i write the tk_putchar*/
}
if(num_printed!=check)
return(-1);
return (num_printed);
}
???
this is my first time to ask in this great forum....
so.... in brief
I'm writing an OS "unix clone" ,and i started with the print functions....
the main two parts in this function is :tk_printf and tk_sprintf
the two function prototype:
1-int tk_printf(const char*, ...);
printf() calls sprintf() to format the pre-formatted string containing unlimited arguments then prints the ouptput of sprintf() on the standard output. returns the number of characters printed on the standard output not including the trailing '\0' used to end output to strings or a negative value if an output error occurs.
2-int tk_sprintf(char*,const char*, ...);
sprintf() formats the pre-formatted string containing unlimited arguments and prints it in a buffer. the 1st parameter is a pointer to the buffer which will contain the formatted string, the 2nd parameter is a pointer to a constant string containing the pre-formatted string, the remaining parameters is the list of arguments as passed in the pre-formatted string.the pre-formatted string uses the same format specifies as the libc printf() function.
i'm using the va_list in the sprintf function to deal with the arguments...
the problem is that when i pass the string from the tk_printf to the tk_sprintf function the va_list in the sprintf can't locate the arguments.
the code of tk_printf function:
int tk_printf(const char* nformatted,...)
{
char buffer[256];
int index=0,num_printed,check,char_num=0,nf_index=0;
num_printed=tk_sprintf(buffer,nformatted);
for(index=0,check=0;num_printed>index;index++,check++)
{
putchar(buffer[index]); /*using the putchar of libc until i write the tk_putchar*/
}
if(num_printed!=check)
return(-1);
return (num_printed);
}
???