Graphics.h question

This is a discussion on Graphics.h question within the Game Programming forums, part of the General Programming Boards category; I want to put a text with variables using a graphic mode but I cant beacause i can only put ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    75

    Graphics.h question

    I want to put a text with variables using a graphic mode but I cant beacause i can only put strings without variables. EX: with outtext I can put "hello", but I cant put ("hello %s",paninaro).

    Is there any function to do this?? I'm designing a game and want to put a scoreboard.
    ---Programming is like roaming, you never know where you'll end at------

    If 'here' is pronounced as 'hear', why 'there' isnt pronounced as 'dear'??

    paninaro3000@yahoo.com

  2. #2
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    It looks like that function accepts strings, so just pass it a string:

    put("Hello ");
    put (variable);
    put("whatever else");

  3. #3
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    two methods,

    1: easy

    Code:
    #include <stdio.h>
    
    
    
    char buf[MAX_OUTPUT_LENGTH];
    
    sprintf(buf,"hello %s",paninaro);
    outtext(buf);
    or

    2: easy

    i dont know what outtext() returns so change accordingly

    Code:
    #include <stdarg.h>
    #define MAX_OUTPUT_LENGTH 256
    
    int out(char* s,...)
    {
        char buf[MAX_OUTPUT_LENGTH];
        va_list list;
        va_start(list,s);
    
        vsnprintf(buf,MAX_OUTPUT_LENGTH,s,list);
    
        va_end(list);
    
        return outtext(buf);
    }
    
    int main(void)
    {
      // code...
    
      out("woo %d",100);
      // ...code
    }
    output:
    ------------------------------

    woo 100
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  2. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 12:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

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