LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   printf() implementation using write() ? (https://www.linuxquestions.org/questions/programming-9/printf-implementation-using-write-475027/)

introuble 08-18-2006 03:32 AM

printf() implementation using write() ?
 
I need to write a printf() implementation using write. Variable argument list, the whole deal. Does anyone know a simple method to achieve this?

jim mcnamara 08-18-2006 05:41 AM

The simplest answer is to review the printf implementation in glibc source.
If this is for fun, great. If not why are you doing this?

printf is a large chunk of code.

lkg 08-19-2006 01:14 AM

Try this one
#include<unistd.h>
int main()
{
int d=10;
char str[100];
sprintf(str,"hai d= %d",d);
write(1,str,sizeof(str));
return 0;
}
Is this You want?

xhi 08-19-2006 03:15 PM

> Does anyone know a simple method to achieve this?

i dont understand the question. if you have to write your own implementation of it, then write your own implementation of it. you will have to study how to use var_arg lists and figure out how to parse the specifiers out of the format string, then sit down and write it.

if it does not have to be your own implementation of it then just look at the printf source and copy it.


All times are GMT -5. The time now is 10:24 AM.