Solved

printing a char in graphics mode

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now