• Advertisement

Archived

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

why can't I use "%d"

This topic is 5672 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 already searched the forum for my problem and found the following solution for it : I need to pass an int into a function that takes a *char as parameter
  
HRESULT OutputText(char *pString, int x, int y, D3DCOLOR FontColor, ...) ;
   
so I did this :
  
OutputText("Framerate : %d", 0, 0, D3DCOLOR_XRGB(255, 255, 255), nFrameRate) ;
   
now I get this on my screen : Framerate : %d What did I do wrong, do I have to include a header file too if I want to use this?!? thanx in advance for any help [edited by - da_cobra on August 11, 2002 8:29:24 AM]

Share this post


Link to post
Share on other sites
Advertisement
The input/output specifiers "&whatever" are part of
stdio.h and can only be used with scanf,printf,fscanf,fprintf etc.

[edited by - nonnus29 on August 11, 2002 8:37:07 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Use sprintf() to format the message before you call OutputText()

Share this post


Link to post
Share on other sites
"Use sprintf() to format the message before you call OutputText() "

Then why does the OutputText function have "..." as its last argument? It must be some other sort of functionality? (aside from printf style formatting). I''m curious as to what functionality that is exactly...

Share this post


Link to post
Share on other sites
ok ok I got it to work, but what I don''t understand is why it shows :

Framerate : 0

when I go in debugging mode it should display around 60

this is mu OutputText() function


  
HRESULT OutputText(char *pString, int x, int y, D3DCOLOR FontColor, ...)
{
char buffer[256] ;
va_list list ;
va_start(list, pString) ;
int ret = _vsnprintf(buffer, 256, pString, list) ;
if( ret == 256 ) buffer[255] = ''\0'' ;
va_end(list) ;

RECT FontRect = { x, y, 0, 0 } ;
HFONT hFont ;
HRESULT hr ;

hFont = (HFONT)GetStockObject(SYSTEM_FONT) ;

if(pFont)
{
pFont->Release() ;
pFont = NULL ;

}

if FAILED(D3DXCreateFont(g_lpDevice,hFont, &pFont))
{
Write2Log("Failed to Initialize font") ;
return E_FAIL ;
} // end of if


pFont->Begin() ;
pFont->DrawTextA(buffer, -1, &FontRect, DT_CALCRECT, 0) ;
hr = pFont->DrawTextA(buffer, -1, &FontRect, nAlign, FontColor) ;

pFont->End() ;
return hr ;
} // end of OutputText()

Share this post


Link to post
Share on other sites
... means "any type and number of arguments"

It says "you can pass whatever you want to this function"

Share this post


Link to post
Share on other sites
quote:
Original post by niyaw
make pString the last parameter to your function.

... not the last I should say, but before the ''...''

Share this post


Link to post
Share on other sites

  • Advertisement