Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

printing a char in graphics mode

Posted on 2002-05-04
3
376 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

856 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