Basic question on use of StringCchPrintf function.

Started by EdPellesC99, April 22, 2010, 12:24:39 AM

Previous topic - Next topic

EdPellesC99

   Though I read that the StringCchPrintf function replaces the printf function, as I understand it ..... It actually seems to just add a prior step.
With StringCchPrintf, you are safely writing a string to a buffer.

You must then use the printf function (or another deprecated variation) to dump the buffer to the console window. Correct?

 If true, wouldn't you usually need to have #define strsafe_no_deprecate ?  
.....in order to print the string to the console window?

There is no way to use StringCchPrintf alone to both write the buffer and dump it to the console window, am I right?

 Thanks, Ed

AlexN

#1
As I understand the StringCchPrintf-function, you can use it in this way:
#include <stdio.h>
#include <strsafe.h>

int main()
{
char Str[20];

if (S_OK == StringCchPrintfA(Str, sizeof(Str),"Hello %s", "world"))
{
puts(Str);
}

return 0;
}

You also can look at: http://msdn.microsoft.com/en-us/library/ms647541%28VS.85%29.aspx
best regards
Alex ;)

JohnF

Ed, the StringCchPrintf function does not act like the printf function, it is more like the sprintf function.

John

EdPellesC99

Tx Alex,

And John

I forgot to ck notify me of replies. (Just got this).

and yes I see John .....

Tx, Ed