Link to home
Start Free TrialLog in
Avatar of AngelFireMateo
AngelFireMateo

asked on

printing a char in graphics mode

How can I print a character in graphics mode with the
outtextxy function? I'm doing the following:

#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
#include <ctype.h>


void main()
{

   int gdriver = DETECT, gmode;
   int Errcode   ;
   char key;

 initgraph(&gdriver,&gmode,"D:\\BORLAND\\BORLANDC\\BGI\\") ;
 Errcode = graphresult();
 if (Errcode != grOk)
    {
      cout<<"Graphics Error:"<< grapherrormsg(Errcode);
      exit(1);
    }
     setcolor(15);
     key=getch();        
     outtextxy(10,30,key);
}

How can I print key with this function?


Thanks in advance

   AFM





 
ASKER CERTIFIED SOLUTION
Avatar of jdrescher
jdrescher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of baclay
baclay

John's code does solve your problem and here is an alternative that I came up with.

Barry


#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
#include <ctype.h>


struct key_word
{
   unsigned int key_code;
};

struct key_bytes
{
   unsigned char ascii;
   unsigned char scan_code;
};

union key_fields
{
   struct key_word kw;
   struct key_bytes kb;
};


union key_fields key;

void main()
{

  int gdriver = DETECT, gmode;
  int Errcode;
  int c;
  char msgbuf[80];

  initgraph(&gdriver, &gmode, "D:\\BORLAND\\BORLANDC\\BGI\\") ;
  Errcode = graphresult();

  if (Errcode != grOk)
    {
      cout<<"Graphics Error:"<< grapherrormsg(Errcode);
      exit(1);
    }

  setcolor(15);

  key.kw.key_code = getch();


  memset(msgbuf , '\0', 80);
  msgbuf[0] = key.kb.ascii;

  outtextxy(10, 30, msgbuf);
} // end main()
Avatar of AngelFireMateo

ASKER

it works well thanks