Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

outextxy using BGI

Does anyone know a way to outtextxy a variable to the

screen while using the BGI graphics interface?


ie something like


outextxy(100,100,"the number is %d",number);





Comments

  • : Does anyone know a way to outtextxy a variable to the

    : screen while using the BGI graphics interface?


    : ie something like


    : outextxy(100,100,"the number is %d",number);


    ______________________________________________


    The Borland outtext() function looks like this...


    void outtext(char *textstring);


    ...which means that you need to pass it a character string. You wanted to know how to pass it a variable. Well if your variable is a string, no problem. It looks like this:


    #include

    #include

    #include


    main()

    {

    char *txt;

    txt = "3.14";

    if( _setvideomode( _VRES256COLOR ) ) {

    _outtext( txt );

    getch();

    _setvideomode( _DEFAULTMODE );

    }

    }




    If you need to pass a variable other than type char, I'm not sure how to do it.




    Regards,

    Derek


  • MichaelJensenMichaelJensen Posts: 2Member
    : : Does anyone know a way to outtextxy a variable to the
    : : screen while using the BGI graphics interface?


    : : ie something like


    : : outextxy(100,100,"the number is %d",number);


    : ______________________________________________


    : The Borland outtext() function looks like this...


    : void outtext(char *textstring);


    : ...which means that you need to pass it a character string. You wanted to know how to pass it a variable. Well if your variable is a string, no problem. It looks like this:


    : #include
    : #include
    : #include


    : main()
    : {
    : char *txt;
    : txt = "3.14";
    : if( _setvideomode( _VRES256COLOR ) ) {
    : _outtext( txt );
    : getch();
    : _setvideomode( _DEFAULTMODE );
    : }
    : }


    :
    : If you need to pass a variable other than type char, I'm not sure how to do it.


    :
    : Regards,
    : Derek
    :
    :
    :

    Those functions that take variables like printf and stuff are really wierd, I don't understand them 100% my self but I've been able to get them to work with font drawing routines that took variables and stuff, I would write another function to get around this one, heres an example that would probably work


    //this part goes in with your prototypes :)
    void outtextf(char *fmt, ...); //this is a valid prototype



    void outtextf(char *fmt, ...) //this is a valid prototype
    {
    char temp[180]; /*change this value to whatever the biggest string you will print is */

    va_list argp; //this takes that ... variable thingy

    va_start(argp, fmt); //more ... variable stuff
    vsprintf(temp, fmt, argp); /*like sprintf, but takes a pointer to the ... variables, called va_lists or something(/
    va_end(argp); //more ... variable stuff

    _outtext( temp ); /*I don't know if this line is right but it should work 'cause temp is a standard array of characters*/
    return;
    }

    //--Mike





Sign In or Register to comment.