Thread: Determining XY Coordinates

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    3

    Exclamation Determining XY Coordinates

    How can i determine the XY coordinates of a character and print the output on the screen and my text file?

    would it be possible to use gotoxy?

    for example:






    void print(ifstream& input, ofstream& output);

    void gotoxy(int x, int y);

    void print(ifstream& input, ofstream& output)


    {
    int x, y;
    COORD coord;
    coord.X = x;
    coord.Y = y;

    ...
    ...
    ...

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    3
    btw, i used the windows.h library.. are there any libraries that I could possibly use?

  3. #3
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    i don't understand what you mean. by "determine the XY coordinates of a character"

    do you mean the line and column number of a particular character in the console buffer or what?

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    3
    by XY, I mean rows,columns

    For example, you are given the following text file and you are to determine the coordinates of Xs..
    XOOXOOXXOX
    XOOXOOOOOX
    XOXXOOOXOO

    The output would be:

    “The coordinates of the # signs are:
    1,1/1,4/1,7/1,8/1,10
    2,1/2,4/2,10
    3,1/3,3/3,4/3,8"

  5. #5
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    ok, so what are you confused about?

  6. #6
    Registered User
    Join Date
    Jul 2009
    Posts
    50
    What code do you have that you can show us? For starters, try putting the contents of the text file into a 2D array and looping through that to find the X's.

  7. #7
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    that's probably not the best strategy imo.

    i would read the file 1 character at a time, while maintaining column and row counters and push_back their current values onto a vector of coords whenever you find the needle in the haystack.
    Last edited by m37h0d; 11-04-2009 at 09:37 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get relative mouse coordinates when GLUT return absolute
    By joeprogrammer in forum Game Programming
    Replies: 14
    Last Post: 02-10-2009, 06:35 PM
  2. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  3. Global coordinates in OpenGL?
    By IcyDeath in forum C++ Programming
    Replies: 1
    Last Post: 11-25-2004, 06:29 PM
  4. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM
  5. Size of 1 pixel
    By ooosawaddee3 in forum C++ Programming
    Replies: 4
    Last Post: 07-26-2002, 08:06 PM

Tags for this Thread