# Finding Y coordinate

• 04-16-2003
Extol
Finding Y coordinate
Ok. I'm trying to find the y coordinate of the first open line an a console screen. as in, the first line of 80 spaces is assumed the first open line. So i have this code.
Code:

```int findy(){         COORD startingPosition={0,0};         int space_count=0;         for(int y=0; y<=CONSOLE_HEIGHT; y++){                 for(int x=0; x<=CONSOLE_WIDTH; x++){                         if(startingPosition.X == SPACE){                                 space_count++;                         }                         startingPosition.X++;                         if(space_count==80){                         return startingPosition.Y;                         }                 }                 space_count=0;                 startingPosition.Y++;         }         return 0; }```
and assuming these definitions are at the top
Code:

```#define CONSOLE_WIDTH 80 #define CONSOLE_HEIGHT 25 #define SPACE ' '```
I don't know if the console is just not spaces or not, or possibly i have some errors. Any help would be nice. Thanks.
• 04-16-2003
Magos
Quote:

if(startingPosition.X == SPACE)
{
space_count++;
}
here, you're not testing if the character at the X position is SPACE, but if the X position itself has the value SPACE (32 I believe).
I don't know of any function to extract a character from the console though...
• 04-16-2003
Extol
Would anyone know of a function that can extract characters from the screen?
• 04-16-2003
Magos
I did find this in Borland's helpfiles. Perhaps you can work something out of it.
Quote:

gettext

Syntax

#include <conio.h>
int gettext(int left, int top, int right, int bottom, void *destin);

Description

Copies text from text mode screen to memory.
gettext stores the contents of an onscreen text rectangle defined by left, top, right, and bottom into the area of memory pointed to by destin.
All coordinates are absolute screen coordinates not window-relative. The upper left corner is (1,1). gettext reads the contents of the rectangle into memory sequentially from left to right and top to bottom.
Each position onscreen takes 2 bytes of memory: The first byte is the character in the cell and the second is the cell's video attribute. The space required for a rectangle w columns wide by h rows high is defined as

bytes = (h rows) x (w columns) x 2

Note: Do not use this function for Win32s or Win32 GUI applications.

Return Value

gettext returns 1 if the operation succeeds.
On error, it returns 0 (for example, if it fails because you gave coordinates outside the range of the current screen mode).

Borland C++ 5.0 Programmer's Guide