Archived

This topic is now archived and is closed to further replies.

GDI TextOut Problem

This topic is 5573 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to print the value of a variable, but if var=5 TextOut print 5, and i want to be printed 05, how can i do it? char s[2]; itoa(time.wSecond,&s,10); TextOut(hDC,0,0,s,strlen(s)); // out s[0] = "2" s[1] = "1" out: 21 but if i want to put 01, it print only 1 thnx

Share this post


Link to post
Share on other sites
Try using sprintf instead of itoa. You might have to enlarge the buffer a little to account for the terminator

sprintf(str,"%02d",time.wSecond);

"%02d" - the 02 before the type specifier indicatates that numbers less than 10 should have a zero prepended to them - that''s the effective outcome at any rate. Read the docs on printf format specifiers to get the proper explaination.

Share this post


Link to post
Share on other sites
sprintf puts something into a string, not print something on the screen

PSTR str;
int mynumber;
mynumber=2;
wsprintf(str,"%02d",mynumber);
TextOut(bdc,100,100,str,strlen(str)-1);

--Fireking

Owner/Leader
Genetics 3rd Dimension Development

Share this post


Link to post
Share on other sites
Fireking's example doesn't allocate any memory for str - so there's no buffer there and thus you get the error. The char array that you initially began with should do the trick

char str[4]; // one extra byte for the terminator, one extra for padding

sprintf(str,"%02d",mynumber);

and so forth as fireking showed.

// edit:

in the format specifier - 02 - the zero indicates that leading spaces should be filled with 0 and the 2 indicates the minimum size to use. So if mynumber requires more than 2 digits those will get printed as well.

[edited by - lessbread on September 9, 2002 6:30:02 PM]

Share this post


Link to post
Share on other sites