Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

format specifiers

Status
Not open for further replies.

ADoozer

Programmer
Dec 15, 2002
3,487
AU
can anyone point me in the direction of a complete list of format specifiers (%s, %d. %f, etc) in c/c++

im trying to find out why a particular string causes a function to crash when using va_start macro with _vsnprintf

basic code...

Code:
void CServerDlg::WriteConsoleString(LPCTSTR pMsg, ...)
{
	TCHAR		str[500];
	va_list		marker;
	int			nLen;

	va_start(marker, pMsg);
	_vsnprintf( str, sizeof( str ) - 1, pMsg, marker );
	va_end(marker);

}

any input appreciated

If somethings hard to do, its not worth doing - Homer Simpson
 
What's a true problem?
This snippet is OK (if your pMsg is a right format string and no errors in _vsnprintf;)...
 
sizeof(str) - 1 isn't a good idea if you are using unicode. It should be (sizeof(str)/sizeof(str[0]) - 1

Is one of your strings a CString that hasn't been LPCTSTRed?
 
hi, this isnt my code, its a snippet from a game server code (aliens vs. predator 2)

im not concerned at the moment with practical programming practices, i just need to find out what is causing a particular string to crash the server app (so i can do a quick patch) but im completely self taught and i only know the basic format specifiers.

example string

"aaaa%1.f%1.f%1.f%1.f%1.f%1.f%x%x%1.f%x%x%1.f%1.f%1.f%1.f%1.f%1.f%x %n"

apparently the call should be :-

WriteConsoleString("%s",UserStr)

but in the code it is called :-

WriteConsoleString( UserStr )

thnxs for any input

If somethings hard to do, its not worth doing - Homer Simpson
 
If you pass this format string to this WriteConsoleString, you will have unpredicated behaviour because of this format assumed 6 double arguments, then int arg, then double etc...
WriteConsoleString(UserStr) has no any args after format (but _vsnprintf wants them;).
It's a rather strange situation.
 
unpredicated behaviour

yup thats what im trying to fix.

ive found a temporary fix (which ive been using for several months, [although i only filtered %n]) its easier to filter in the DLL before the CEDIT box sees the formated code.

quick question on format specifiers...

is %1.f the same as %.1f

thnx

If somethings hard to do, its not worth doing - Homer Simpson
 
%1.f and %.1f are both %f. In this aspect (where are arguments for %f?) they are identical. The last specifier specifies one digit after decimal point - that's all.

No printed arguments in your case: va_list marker pointer refers to a garbage in the program stack (may be NaN etc).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top