Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / How to use dbPrint like printf

Author
Message
Kitiara
12
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 18th Feb 2012 23:55 Edited at: 19th Feb 2012 06:29
Here it is:

Example of Usage: Write("%u %s TEN", 10, "means"); (Maximum 10 variables)
xix psycho xix
16
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 19th Feb 2012 05:56 Edited at: 19th Feb 2012 06:05
If you are looking for a more flexible function that does not have an argument limit, here is how the original printf works :



This will allow you to use dbPrintf exactly like printf, but there is obviously some formatting parameters missing. You can append char *s, chars, and ints in this version. Additional TODO items would be: "%x", "%X", "%f", and others.

Edit: I just realized that it seemed like i was trying to one-up you!!! I'm sorry I wasnt trying to do that I just figured I would help out if I could!!!
Kitiara
12
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 19th Feb 2012 06:37
Yes, this is an option too but i think the first one is more safe and faster. By the way, I understand your intent, don't worry .
WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 19th Feb 2012 20:09
Another option which I use is to have a temp char buff:



The char buffer is assigned on the stack and doesn't leave a footprint on the files size.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
xix psycho xix
16
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 19th Feb 2012 23:35
Lol I'm not quite sure how the first way is faster OR safer I wouldn't mind hearing your reasoning behind that though. Maybe I am just not understanding the differences in the code? BTW I'm just trying to learn, I just want to see what your side is I don't want people to think I'm a big jerk lol.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 19th Feb 2012 23:46
Here's how I do it:



Just another option...

JTK
Kitiara
12
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 20th Feb 2012 23:09
I have tried va_start before but wasn't working properly in DarkGDK. Did you tried ? Is this working without a problem ?

Physcho, i said first is faster and safer than second because according to the second, the function will make some calculations and also it is a lot more possible that making mistakes so if you make then you will have to fix it.
xix psycho xix
16
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 21st Feb 2012 16:49
I guess I can see your point there, but the only way that the code will make a calculation error is if the programmer does And yes, that code works fine for me with darkgdk, just include <stdarg.h> and it works fine.
Kitiara
12
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 21st Feb 2012 20:54
Oh then the fourth is better then the others, very well.
Kitiara
12
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 21st Feb 2012 20:54
Oh then the fourth is better then the others, very well.

Login to post a reply

Server time is: 2024-11-23 00:18:33
Your offset time is: 2024-11-23 00:18:33