Skocz do zawartości

wsprintf - stare i niejare


Zyziu

Recommended Posts

Z tego co piszą w MSDNie to funkcja wsprintf obsługuje tylko następujące formaty:

c A single character. This sequence is interpreted as type WCHAR when the calling application uses the #define UNICODE compile flag and as type CHAR otherwise.
C A single character. This sequence is interpreted as type CHAR when the calling application uses the #define UNICODE compile flag and as type WCHAR otherwise.
d A signed decimal integer argument. This sequence is equivalent to the i sequence.
hc, hC A single character. The wsprintf function ignores character arguments with a numeric value of zero. This sequence is always interpreted as type CHAR, even when the calling application uses the #define UNICODE compile flag.
hd A signed short integer argument.
hs, hS A string. This sequence is always interpreted as type LPSTR, even when the calling application uses the #define UNICODE compile flag.
hu An unsigned short integer argument.
i A signed decimal integer. This sequence is equivalent to the d sequence.
lc, lC A single character. The wsprintf function ignores character arguments with a numeric value of zero. This sequence is always interpreted as type WCHAR, even when the calling application does not use the #define UNICODE compile flag.
ld A long signed decimal integer. This sequence is equivalent to the li sequence.
li A long signed decimal integer. This sequence is equivalent to the ld sequence.
ls, lS A string. This sequence is always interpreted as type LPWSTR, even when the calling application does not use the #define UNICODE compile flag. This sequence is equivalent to the ws sequence.
lu A long unsigned integer.
lx, lX A long unsigned hexadecimal integer in lowercase or uppercase.
s A string. This sequence is interpreted as type LPWSTR when the calling application uses the #define UNICODE compile flag and as type LPSTR otherwise.
S
A string. This sequence is interpreted as type LPSTR when the calling application uses the #define UNICODE compile flag and as type LPWSTR otherwise.
u An unsigned integer argument.
x, X An unsigned hexadecimal integer in lowercase or uppercase.

Jak widać nie ma wśród nich odpowiedniego dla liczb zmienno przecinkowych (chociaż bardzo mnie to dziwi). Mozesz sprobowac zamiast wsprintf uzyc sprintf - z niąpowinno być wszystko w porządku.

Link do komentarza
Udostępnij na innych stronach

bool _ftoa (TCHAR *szStr, double d)
{
        if (!szStr)
                return false ;

        gcvt (d, 15, szStr) ;
        if (szStr [lstrlen (szStr) - 1] == '.')
                szStr [lstrlen (szStr) - 1] = '\0' ;
return true ;
}

float v ;
TCHAR szV [32] ;

_ftoa (szV, (double) v) ;
wsprintf (buf, TEXT ("wynik = %s mag"), szV) ;

Spróbuj w ten sposób. Pozdrawiam.

Link do komentarza
Udostępnij na innych stronach

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gość
Odpowiedz...

×   Wkleiłeś zawartość bez formatowania.   Usuń formatowanie

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Utwórz nowe...