TextOut equivalent for numbers?

This is a discussion on TextOut equivalent for numbers? within the C++ Programming forums, part of the General Programming Boards category; Does anyone know if there is an "TextOut" equivalent function for numbers? I need to draw some floating point numbers, ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    26

    TextOut equivalent for numbers?

    Does anyone know if there is an "TextOut" equivalent function for numbers? I need to draw some floating point numbers, or at least integers on screen in the WM_PAINT case. I am able to draw text like so: TextOut(hdc, 695, 125, "Hello", 10); but I need something similar for float or integers.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,341
    You sprintf() it to a string, then output the string you've created.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    26
    Ok, works for the most part, but there is some garbage at the end of the string. Something like this:

    http://img9.echo.cx/img9/73/gb5ra.jpg

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    That looks like you are going out of bounds on your char array. You may need to tack on a '\0' char at the end of your data to signal the end of the string.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,341
    You have to work pretty hard to make sprintf() omit the \0 at the end of the string.
    More likely, it's one of

    Code:
    char buff[2]; // too small
    sprintf( buff, "%d", myint );
    Code:
    char *buff; // not allocated
    sprintf( buff, "%d", myint );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer equivalent to array notation
    By bekkilyn in forum C Programming
    Replies: 4
    Last Post: 12-06-2006, 07:22 PM
  2. Replies: 10
    Last Post: 08-17-2005, 11:17 PM
  3. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 10:31 PM
  4. TextOut() flickering
    By Xterria in forum Game Programming
    Replies: 6
    Last Post: 01-22-2004, 08:55 PM
  5. ::TextOut vs CDC::TextOut
    By bonkey in forum Windows Programming
    Replies: 4
    Last Post: 11-08-2002, 02:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21