LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-18-2006, 03:32 AM   #1
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Rep: Reputation: 31
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?
 
Old 08-18-2006, 05:41 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
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.
 
Old 08-19-2006, 01:14 AM   #3
lkg
LQ Newbie
 
Registered: Aug 2006
Posts: 13

Rep: Reputation: 0
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?

Last edited by lkg; 08-19-2006 at 01:20 AM.
 
Old 08-19-2006, 03:15 PM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
> 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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mac OS X and Debian Linux LAN implementation write-up Chinook Linux - Networking 1 02-02-2006 12:51 PM
printf problem??? Mistro116@yahoo.com Programming 2 11-13-2005 08:45 PM
c printf question. fredgt Programming 5 09-09-2004 05:06 AM
Using 'printf' on a 'struct' skywalker27182 Programming 10 12-20-2003 12:06 PM
printf new_user10 Programming 3 09-09-2003 11:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration