Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Easy 40pts. outtextxy

Posted on 2003-03-14
Medium Priority
Last Modified: 2008-02-01
Ok, this is easy and i am sure the first person to answer this will get it. I am using Turbo C++, Dos, and i just plain forgot how to outtextxy a varible. Example:

//In a game i have:
int hits=2;
// I want to outext xy this to the screen
int hittemp[10]; //i remember i had to do this
printf(/*i forget what to put in here*/);
outextxy(100,100,/*i forget what to put here to*/);
please help! Tell me how to fix this! Thanks!
Question by:Punkman
  • 4
  • 2

Accepted Solution

DarthNemesis earned 160 total points
ID: 8140995
outtextxy.... that's a BGI function, isn't it? If you're not in graphics mode, that would be a problem. The third parameter for outtextxy is, of course, the character string you want to print. To display hits you need to create a character array the length of your hits variable (plus 1 for the \0 character), and store the variable into that array.
if hits is less than 10:
   char hittemp[2];
   hittemp[0] = hits+'0';
if hits is greater than/equal to 10:
   char hittemp[3];
   hittemp[0] = (hits/10)+'0';
   hittemp[1] = (hits%10)+'0';

then just outtextxy(100,100,hittemp);

Author Comment

ID: 8141123
Ya, i am in graphics mode. I forgot! The reason i hade an array (i don't think you need one) is beause the last time i used it it was to output a varible that was a letter. Lets just say hits is a changing varible, it could be 1 or 2 or 6. I remember you had to convert it, but i am pretty sure you hade to use
//and then
outtextxy(100,100,hittemp or something)
right? I think i understand what you are saying.

Author Comment

ID: 8141127
no, wait you did have to use an array...i think...
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Expert Comment

ID: 8141144
Yeah I see what you're saying. You're using printf() to store the int into the char array instead of doing it manually. That should be fine, but you still have to ensure you allocate enough characters to store the variable when you declare hittemp.

Author Comment

ID: 8141197
So it would be like:

int hit=2;
int(or char?) temphit[10];
outtextxy(100,100,temphit(or hit?);

would that be right?

Author Comment

ID: 8141324
I get it! Ok i see exactly what you mean! It would be like this:

char hittemp[10];
int hit=2;
sprintf(hittemp,"%d",hit); //note not printf like i thought

There just like that. Thanks, i give you the points.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 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.
Suggested Courses

580 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