Thread: Printing to a specific coordinate of the console

  1. #1
    Registered User
    Join Date
    Jan 2016
    Posts
    7

    Printing to a specific coordinate of the console

    So as the title says, I would like to find out how to print to a certain coordinate of the console. For now, i just want to do a single number. If someone could explain this with some code as well that would be appreciated, thanks.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,615
    In windows, you can call this: WriteConsoleOutputCharacter function (Windows) See the COORD parameter? That's where you set your location.

    Code:
    #include <windows.h>
    #include <string.h>
    #include <stdlib.h>
    int main(void)
    {
        HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
        if (hout == INVALID_HANDLE_VALUE) {
             return EXIT_FAILURE;
        }
        SHORT x = 7, y = 3;
        DWORD dwWritten = 0;
        COORD cursor = {x, y};
        const char cs[] = "122333";
        WriteConsoleOutputCharacter(hout, cs, strlen(cs), cursor, &dwWritten); 
        Sleep(5000);
        return EXIT_SUCCESS;
    }

  3. #3
    Registered User
    Join Date
    Jan 2016
    Posts
    7
    Thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 02-23-2015, 11:37 AM
  2. Replies: 5
    Last Post: 04-30-2012, 12:44 AM
  3. Printing a specific number of digits
    By JizJizJiz in forum C++ Programming
    Replies: 4
    Last Post: 06-28-2006, 08:14 PM
  4. Console App., Hide specific folder
    By nextstep in forum C++ Programming
    Replies: 10
    Last Post: 03-28-2005, 05:28 AM
  5. location specific console colors
    By bennyandthejets in forum C Programming
    Replies: 7
    Last Post: 07-24-2002, 07:32 AM

Tags for this Thread