From: Sonu on
Thanks guys,
I must be spacing out (as I seem to have been doing that often these days)
when I was using that %a instead of %c.
Definitely want to move to CString.... Though I'll have sit down and go
through my whole project and replave all this char stuff...
It's also giving the decremented error everywhere all over in VC2005, so now
I have a good excuse to use CString everywhere!

Thanks a bunch as ususal...

"David Webber" wrote:

>
> "Vipin" <Vipin(a)nospam.com> wrote in message
> news:uxxt2Y1sGHA.4080(a)TK2MSFTNGP03.phx.gbl...
>
> > Good thing to use is this:-
> > CString str;
> > str.Format(_T("%c") , 'a' + j);
>
> Better is
>
> str.Format(_T("%c") , _T('a') + j );
>
> Dave
> --
> David Webber
> Author MOZART the music processor for Windows -
> http://www.mozart.co.uk
> For discussion/support see
> http://www.mozart.co.uk/mzusers/mailinglist.htm
>
>
>
>
>
From: Sonu on
Thanks guys,
I must be spacing out (as I seem to have been doing that often these days)
when I was using that %a instead of %c.
Definitely want to move to CString.... Though I'll have sit down and go
through my whole project and replave all this char stuff...
It's also giving the decremented error everywhere all over in VC2005, so now
I have a good excuse to use CString everywhere!

Thanks a bunch as ususal...

"David Webber" wrote:

>
> "Vipin" <Vipin(a)nospam.com> wrote in message
> news:uxxt2Y1sGHA.4080(a)TK2MSFTNGP03.phx.gbl...
>
> > Good thing to use is this:-
> > CString str;
> > str.Format(_T("%c") , 'a' + j);
>
> Better is
>
> str.Format(_T("%c") , _T('a') + j );
>
> Dave
> --
> David Webber
> Author MOZART the music processor for Windows -
> http://www.mozart.co.uk
> For discussion/support see
> http://www.mozart.co.uk/mzusers/mailinglist.htm
>
>
>
>
>
From: Vipin on
yup

--
Vipin Aravind
http://www.explorewindows.com


"David Webber" <dave(a)musical.demon.co.uk> wrote in message
news:e38Jvm2sGHA.4080(a)TK2MSFTNGP03.phx.gbl...
>
> "Vipin" <Vipin(a)nospam.com> wrote in message
> news:uxxt2Y1sGHA.4080(a)TK2MSFTNGP03.phx.gbl...
>
>> Good thing to use is this:-
>> CString str;
>> str.Format(_T("%c") , 'a' + j);
>
> Better is
>
> str.Format(_T("%c") , _T('a') + j );
>
> Dave
> --
> David Webber
> Author MOZART the music processor for Windows -
> http://www.mozart.co.uk
> For discussion/support see
> http://www.mozart.co.uk/mzusers/mailinglist.htm
>
>
>
>


From: Joseph M. Newcomer on
It cannot be causing a "storage leak" since there is no allocation involved.

You should generally avoid _stprintf whenever possible. Use CString::Format as the
preferred choice. If you MUST use some form like _stprintf, use StringCchPrintf (I think
that's the name, but search for strsafe.h on the MSDN) which at least will avoid any
possibility of buffer overflow

It would help a lot if you did something like

StringCchPrintf(_T("%c"), B, sizeof(B) / sizeof(TCHAR), (BYTE)('a' + i));

This eliminates several problems:
1. No buffer overflow if you make an error
2. The value is not treated as a signed value and therefore sign extended
(see problem 1)

However, your actual problem is even simpler; it would have been better to do
TCHAR B[2];
B[0] = _T('a') + i;
B[1] = _T('\'0');

which eliminates the need to call a subroutine to do a fundamentally trivial computation.

I assume you meant %c because %a is not documented.
joe

On Sat, 29 Jul 2006 13:17:02 -0700, Sonu <sonu(a)online.nospam> wrote:

>Hello all,
>I am having trouble with _stprintf(). It's a Unicode application.
>
>TCHAR B[5];
>_stprintf( B, _T("%a"), 'a' + i);
>
>so if the value if i=9, I want B to be "j". But instead the value in B is
>"-0x1.c39360p+117"
>
>And this is causing all kinds of memory leaks and strange behaviours...
>
>Any help appreciated
>Thanks
>Srishti
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Vipin on
using StringCchPrintf would need linking to strsafe.lib. The issue of buffer
overflow can be handled with snprintf and alike.

--
Vipin Aravind
http://www.explorewindows.com


"Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message
news:e57oc2lrr2nd1j0nt83h8e7h02ahjsbqih(a)4ax.com...
> It cannot be causing a "storage leak" since there is no allocation
> involved.
>
> You should generally avoid _stprintf whenever possible. Use
> CString::Format as the
> preferred choice. If you MUST use some form like _stprintf, use
> StringCchPrintf (I think
> that's the name, but search for strsafe.h on the MSDN) which at least will
> avoid any
> possibility of buffer overflow
>
> It would help a lot if you did something like
>
> StringCchPrintf(_T("%c"), B, sizeof(B) / sizeof(TCHAR), (BYTE)('a' + i));
>
> This eliminates several problems:
> 1. No buffer overflow if you make an error
> 2. The value is not treated as a signed value and therefore sign extended
> (see problem 1)
>
> However, your actual problem is even simpler; it would have been better to
> do
> TCHAR B[2];
> B[0] = _T('a') + i;
> B[1] = _T('\'0');
>
> which eliminates the need to call a subroutine to do a fundamentally
> trivial computation.
>
> I assume you meant %c because %a is not documented.
> joe
>
> On Sat, 29 Jul 2006 13:17:02 -0700, Sonu <sonu(a)online.nospam> wrote:
>
>>Hello all,
>>I am having trouble with _stprintf(). It's a Unicode application.
>>
>>TCHAR B[5];
>>_stprintf( B, _T("%a"), 'a' + i);
>>
>>so if the value if i=9, I want B to be "j". But instead the value in B is
>>"-0x1.c39360p+117"
>>
>>And this is causing all kinds of memory leaks and strange behaviours...
>>
>>Any help appreciated
>>Thanks
>>Srishti
> Joseph M. Newcomer [MVP]
> email: newcomer(a)flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm