Solved

printing a char in graphics mode

Posted on 2002-05-04
3
377 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
[X]
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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Grammars for C C++ and java 1 139
is twain_32.dll cmpatible with windows 10 ? 10 237
c++ aadding data to a list box vs2005 mfc project 7 13
visual C++ 1 9
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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. …
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 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.

726 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