?
Solved

Easy 40pts. outtextxy

Posted on 2003-03-14
6
Medium Priority
?
700 Views
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!
0
Comment
Question by:Punkman
[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
  • 4
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
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);
0
 

Author Comment

by:Punkman
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
printf(something,"%i",hittemp)
//and then
outtextxy(100,100,hittemp or something)
right? I think i understand what you are saying.
0
 

Author Comment

by:Punkman
ID: 8141127
no, wait you did have to use an array...i think...
0
Independent Software Vendors: 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!

 
LVL 2

Expert Comment

by:DarthNemesis
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.
0
 

Author Comment

by:Punkman
ID: 8141197
So it would be like:

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

would that be right?
0
 

Author Comment

by:Punkman
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
outtextxy(100,100,hittemp);

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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 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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

777 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