Text on graphics screen

This is a discussion on Text on graphics screen within the C++ Programming forums, part of the General Programming Boards category; I am using borland C++ 3.1. I am using the code below to display text (a array value) on a ...

  1. #1
    bjbouchard
    Guest

    Text on graphics screen

    I am using borland C++ 3.1.

    I am using the code below to display text (a array value) on a graphic screen. I know I am using the right function (sprintlf() ) but cannot get it to work right.

    struct vertex_struct
    {
    int excess;
    int height;
    } vertex[10];

    I want to display all 5 vertices on the screen:

    char text_string[15];
    for (int c=0; c<5; c++)
    {
    sprintf(text_string, "Vertex[%d] = %lf", c, vertex[c].excess);
    outtextxy(300,400,text_string);
    }

    ************************************************** ***

    I would like the output to look like:

    vertex[0] = 34.05
    vertex[1] = 105.12
    vertex[2] = 33.3
    vertex[3] = 21.2
    vertex[4] = 10

    I know that I am not using sprintlf() correctly. Also the outtextxy () is not correct either because as it is, it just keeps writing to the same spot on the screen.

    I have never used the sprintf function before, so it is giving me some problems.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    12
    first of all, make sure your char* array is big enough to hold the entire string..you can always over-estimate just in case

    char text_string[30];

    sprintf() is just like printf(), the %d identifier is for signed decimal integer (int), %lf is for doubles I believe..

    sprintf(text_string, "Vertex[%d] = %d", c, vertex[c].excess);


    I have never seen outtextxy() before.. maybe use gotoxy() and another func to print at that location, there may be something about this in the board FAQs

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  2. Text adventure engine idea. thoughts?
    By suzakugaiden in forum Game Programming
    Replies: 16
    Last Post: 01-15-2006, 04:13 AM
  3. Graphics Devices and Cprintf clash
    By etnies in forum C Programming
    Replies: 6
    Last Post: 05-09-2002, 11:14 AM
  4. Moving to the next structure array
    By mattz in forum C Programming
    Replies: 2
    Last Post: 11-30-2001, 02:43 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 06:35 PM

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