From: Sonu on 29 Jul 2006 16:17 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
From: Heinz Ozwirk on 29 Jul 2006 16:38 "Sonu" <sonu(a)online.nospam> schrieb im Newsbeitrag news:0C804929-8937-4E1A-8ED9-C29AC4D92EC0(a)microsoft.com... > 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" If you want printf (or any other member of that family) to print a character, you should tell it to print a character and not a signed hexadecimal floatingpoint value. Use %c instead of %a, or even better - forget about printf and scanf and use C++ style input and output streams like std::basic_stringstream. Also, in a Unicode app, use L'a' or even better _T('a') instead of plain 'a'. And for your example, it'd be much easier and faster to replace _strprintf by two simple assignments: B[0] = _T('a') + i; B[1] = 0; Finally, don't use identifiers with only upper case characters for anything but #define'd macro names. It might save you a lot of problems in the future. HTH Heinz
From: Vipin on 29 Jul 2006 17:30 I suggest we don't use stprintf anymore in programming. I have made it a rule for myself not to use raw character arrays as far as possible. Good thing to use is this:- CString str; str.Format(_T("%c") , 'a' + j); -- Vipin Aravind http://www.explorewindows.com "Heinz Ozwirk" <hozwirk.SPAM(a)arcor.de> wrote in message news:44cbc739$0$24896$9b4e6d93(a)newsread4.arcor-online.net... > "Sonu" <sonu(a)online.nospam> schrieb im Newsbeitrag > news:0C804929-8937-4E1A-8ED9-C29AC4D92EC0(a)microsoft.com... >> 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" > > If you want printf (or any other member of that family) to print a > character, you should tell it to print a character and not a signed > hexadecimal floatingpoint value. Use %c instead of %a, or even better - > forget about printf and scanf and use C++ style input and output streams > like std::basic_stringstream. > > Also, in a Unicode app, use L'a' or even better _T('a') instead of plain > 'a'. > > And for your example, it'd be much easier and faster to replace _strprintf > by two simple assignments: > > B[0] = _T('a') + i; > B[1] = 0; > > Finally, don't use identifiers with only upper case characters for > anything but #define'd macro names. It might save you a lot of problems in > the future. > > HTH > Heinz
From: David Webber on 29 Jul 2006 19:49 "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: David Webber on 29 Jul 2006 19:49
"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 |