Thread: Finding Y coordinate

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    70

    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.
    Last edited by Extol; 04-16-2003 at 09:37 AM.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    70
    Would anyone know of a function that can extract characters from the screen?

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I did find this in Borland's helpfiles. Perhaps you can work something out of it.
    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
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. liniting values of a custom coordinate
    By sh3rpa in forum C++ Programming
    Replies: 3
    Last Post: 11-11-2007, 05:22 PM
  2. Program compiles; won't build
    By Kayoss in forum C++ Programming
    Replies: 1
    Last Post: 05-12-2006, 09:46 AM
  3. Trying to convert vectors from cartesian coordinate
    By FALSTON01 in forum C++ Programming
    Replies: 1
    Last Post: 10-20-2005, 05:17 PM
  4. MFC :: Finding Child Window of a CWnd* Object?
    By SyntaxBubble in forum Windows Programming
    Replies: 2
    Last Post: 09-06-2003, 09:06 AM
  5. Class rectangle/need help thanks!!!
    By C++Newbie in forum C++ Programming
    Replies: 11
    Last Post: 11-16-2001, 04:00 PM