How do you position text?

support for the powerpc toolchain
Post Reply
FireFreek
Posts: 1
Joined: Tue Jul 21, 2009 3:16 am

How do you position text?

Post by FireFreek » Tue Jul 21, 2009 3:24 am

I'm somewhat of a new programmer. I know some java and C++(console apps only), but i've been reading the tutorials on codemii.com, and they've been extremely helpful in getting me stated. So far i understand the first few(up till file management, but i have no need for that now.) so i'm trying to see if i can make a game from what I know. So here's just the first a few probably easy questions:

How do you position text at a certain part of the screen? I know you use printf() to output text, but that just goes down the screen, is there anyway to position it at a certain part of the screen, and have it overwrite whatever was there before, such as a score display?

User avatar
jespa
Posts: 1
Joined: Sun Aug 23, 2009 9:34 pm

Re: How do you position text?

Post by jespa » Sun Aug 23, 2009 9:40 pm

The console understands VT terminal escape codes, which mean that writing some special codes the printf will change the cursor position or the color of the text.

For example, to position the cursor on row 2, column 0

printf("\x1b[2;0H");


Or you can can use variables to make a generic goto function

printf ("\x1b[%d;%dH", row, column );

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 0 guests