Thread: TextOut equivalent for 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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  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,663
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

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, 08: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, 11:31 PM
  4. TextOut() flickering
    By Xterria in forum Game Programming
    Replies: 6
    Last Post: 01-22-2004, 09:55 PM
  5. ::TextOut vs CDC::TextOut
    By bonkey in forum Windows Programming
    Replies: 4
    Last Post: 11-08-2002, 03:11 PM