How do I write the text in printTextScreen(); ?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Acegikmo
Posts: 15
Joined: Sat Jul 19, 2008 1:18 am

How do I write the text in printTextScreen(); ?

Post by Acegikmo »

Another question how to write something :)

extern void printTextScreen(int x, int y, const char* text, u32 color);

How do I write the text?
I want it to show the value of this variable:

double dist;

But this doesn't work:

printTextScreen(32, 32, dist, 0xFFFFFFFF);
pspZorba
Posts: 156
Joined: Sat Sep 22, 2007 11:45 am
Location: NY

Post by pspZorba »

never used this function but from its prototype:

char buffer[42];
sprintf( buffer,"%lf", dist);
printTextScreen(32, 32, buffer, 0xFFFFFFFF);
--pspZorba--
NO to K1.5 !
Acegikmo
Posts: 15
Joined: Sat Jul 19, 2008 1:18 am

Post by Acegikmo »

Works great :)
But could you explain what this line does?
sprintf( buffer,"%lf", dist);

I mean, what's "%lf" ?
pspZorba
Posts: 156
Joined: Sat Sep 22, 2007 11:45 am
Location: NY

Post by pspZorba »

your printTextScreen needs a char * .

you want to print a double (dist, so you have to translate the double into a string. sprintf does the job.

sprintf needs a string ( buffer) that will contain the string, the variable you want to translate (dist) and the format => "%lf"

lt means the variable (dist) is a double.

If you wanted to transform an integer you would have set "%d".
--pspZorba--
NO to K1.5 !
Acegikmo
Posts: 15
Joined: Sat Jul 19, 2008 1:18 am

Post by Acegikmo »

What about float variables?
hibbyware
Posts: 78
Joined: Wed Mar 28, 2007 10:29 am

Post by hibbyware »

WosRet
Posts: 14
Joined: Wed Apr 23, 2008 3:20 am
Location: Confoederatio Helvetica

Post by WosRet »

for float use: "%f".
see this http://www.opengroup.org/onlinepubs/007 ... rintf.html page for more information about using conversion specification
Acegikmo
Posts: 15
Joined: Sat Jul 19, 2008 1:18 am

Post by Acegikmo »

Thanks :)
Post Reply