printf... how to do it?

Programming, for all ages and all languages.
eddyb

printf... how to do it?

Post by eddyb »

i need to write some functions....
yah and i am at printf :? ...

Code: Select all

int printf ( const char * format, ...);
i thinked at a method, but i heve no idea how to get something from that
... (the args). have anyone a idea?
Last edited by eddyb on Sun Mar 09, 2008 5:16 am, edited 2 times in total.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Yeah, nick vsprintf from linux 0.01 and build around that. That's what I and most people do. Printf is hugely monolithic and difficult to debug without... you guessed it, printfs!
princeharrry
Posts: 1
Joined: Thu Dec 27, 2007 3:53 am
Contact:

Printf

Post by princeharrry »

Maybe you find this interesting :
http://freenet-homepage.de/puppylinux/index.html
This what I am working on, it is for Dex OS ,output is fasm but
i think you could easy adapt the funktions.
If you need halp let me know.! :) :)
Hope it help :!:
Bye
eddyb

Post by eddyb »

thanks for help, but i need only a tip for how i can use something "hidden" in that ...
Knows anyone?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

STFW!! STFW!!

Google for variable argument lists!
eddyb

Post by eddyb »

yah i found :)
but i'm at writing strcat and this don't work(work, but only if the string is empty)

Code: Select all

char *strcat(char *destination[], const char *source[])
{
	int i;
	for(i=0;i<strlen(source);i++)
		destination[i+strlen(destination)] = source[i];
	return destination;
}
:roll:
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post by lukem95 »

http://www.koders.com/c/fid2BD5D01DE7B9 ... B519C.aspx

Look at all the sources in that lib, it will tell you how to implement all the string functions etc.

as for printf, i stole it from linux 1.0 as JamesM suggests. Its very easy to port.
~ Lukem95 [ Cake ]
Release: 0.08b
Image
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Post by piranha »

Yeah, nick vsprintf from linux 0.01 and build around that. That's what I and most people do. Printf is hugely monolithic and difficult to debug without... you guessed it, printfs!
Ya know, I opened this thread thinking "I'll add that Linux 0.01 printf is easy to port", and you guys beat me to it.

And use the Linux 0.01 version, there are less file that you don't need so you find the file easier.

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
eddyb

Post by eddyb »

i like to do it, and is very simple
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Post by jzgriffin »

lukem_95 wrote:http://www.koders.com/c/fid2BD5D01DE7B95EC45A02D8BB25D555988ADB519C.aspx

Look at all the sources in that lib, it will tell you how to implement all the string functions etc.
MinGW improperly implements some things...
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

i like to do it, and is very simple
No it's not. Not to do it properly (including hex/octal/decimal numbers, padding with 0/space to user defined lengths, the '%*' specifier...)
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

PDCLib printf() doesn't do floating points (yet), but is otherwise complete (padding, alignment, ...) and - it's Public Domain, meaning you don't have to place your printf() under GPL as you would have if you took Linux as a starting point. See my signature.
Every good solution is obvious once you've found it.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

Solar wrote:PDCLib printf() doesn't do floating points (yet), but is otherwise complete (padding, alignment, ...) and - it's Public Domain, meaning you don't have to place your printf() under GPL as you would have if you took Linux as a starting point. See my signature.
I don't think the initial Linux kernel release was under the GPL, it was under fairly simplistic licence that simply disallowed selling it commercially IIRC.

But I agree, even that is a bit... restrictive. :wink:
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Post by jzgriffin »

I don't actually even remember there being a license for 0.01...just a copyright. Can't remember.

On the topic of printf()'s, you could use Chris Giese's doprintf and friends. There doesn't seem to be a copyright anywhere, so I'm assuming it's public domain. Some things aren't implemented, but it gives a nice base to extend upon.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

Let's say the pre-GPL license is even more unwieldly, as it doesn't even say anything about derivative works. ;-)
Every good solution is obvious once you've found it.
Post Reply