why can't I use "%d"

Started by
7 comments, last by da_cobra 21 years, 8 months ago
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]
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]
Use sprintf() to format the message before you call OutputText()
"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...
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()  
make pString the last parameter to your function.
... means "any type and number of arguments"

It says "you can pass whatever you want to this function"
daerid@gmail.com
quote:Original post by niyaw
make pString the last parameter to your function.

... not the last I should say, but before the ''...''
"after many years of singularity, i'm still searching on the event horizon"
hey that worked thanx alot!!!!!!!

This topic is closed to new replies.

Advertisement