Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor position in a DOS window?

Status
Not open for further replies.

Chriskoenig

Programmer
Jul 23, 2000
3
US
It's a sad story, but I'm still in the DOS console phase of my C++ education. I honestly can't wait for the day I discover graphics. Until then, however, I'm stuck in the ugly world of text. So, to get to my point, I was wondering how to change the cursor position in a regular, 25x80 DOS window. I know how to do it in QBasic (I can already hear you guys laughing) with the Locate command, but I have no idea if C++ has anything that'll do it.
Thanks a lot, guys.
 
For your convenience, I have called it Locate:

#include <windows.h>
#include <stdio.h>

void Locate ( int row, int col )
{ if ( row < 0 || row > 24 ) return;
if ( col < 0 || col > 79 ) return;
COORD c = { (SHORT)col, (SHORT)row };
SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), c ); }

void main ( )
{ int row;
int col;
printf ( &quot;Row (0-24): &quot; ); scanf ( &quot;%d&quot;, &row );
printf ( &quot;Col (0-79): &quot; ); scanf ( &quot;%d&quot;, &col );
Locate ( row, col );
printf ( &quot;This text is starting at row %d, column %d\n&quot;, row, col ); }


Marcel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top