Solved

printing a char in graphics mode

Posted on 2002-05-04
3
375 Views
Last Modified: 2010-04-02
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





 
0
Comment
Question by:AngelFireMateo
3 Comments
 
LVL 1

Accepted Solution

by:
jdrescher earned 50 total points
ID: 6991306
You are still using borland BGI graphics? I have not done this in the last 6+ years..

Here is my guess. I assume outtextxy takes a string and you are giving it a char. I'm sorry if this is totally off base but I don't have any access to borland bgi anymore.

void main()
{

  int gdriver = DETECT, gmode;
  int Errcode   ;
  char key[2];

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

John
0
 

Expert Comment

by:baclay
ID: 6992166
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()
0
 
LVL 1

Author Comment

by:AngelFireMateo
ID: 7150100
it works well thanks
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question