Trouble printing character in console window.

This is a discussion on Trouble printing character in console window. within the Windows Programming forums, part of the Platform Specific Boards category; I'm completely flummoxed by the code below for a simple console program. I can print the character at the corners ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    241

    Trouble printing character in console window.

    I'm completely flummoxed by the code below for a simple console program.

    I can print the character at the corners except for the bottom right.
    If I uncomment the lines to do so the window seems to scroll up a line.

    What's going on?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    
    #define CH 219
    #define COLS 80
    #define ROWS 25
    
    static void set_coord(int x, int y,HANDLE console_handle);
    
    int main(void)
    {
       
    
        CONSOLE_CURSOR_INFO cci;
        COORD buffersize = {COLS,ROWS};
        HANDLE console_handle;
    
        cci.dwSize = 1;
        cci.bVisible = 0;
    
        console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleScreenBufferSize(console_handle, buffersize);
        SetConsoleCursorInfo(console_handle,&cci);                 // hide cursor
    
        set_coord(0,0,console_handle);
        printf("%c",CH);
    
        set_coord(79,0,console_handle);
        printf("%c",CH);
    
        set_coord(0,24,console_handle);
        printf("%c",CH);
    
        //set_coord(79,24,console_handle);
        //printf("%c",CH);
        //set_coord(0,0,console_handle);
    
        getchar();
        return 0;
    }
    
    static void set_coord(int x, int y,HANDLE console_handle)
    {
        COORD coord;
        coord.X = x;
        coord.Y = y;
    
        SetConsoleCursorPosition(console_handle, coord);
    }
    Last edited by gemera; 05-17-2013 at 10:10 PM.

  2. #2
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    241
    I've just realised it's due to the cursor moving on. duh!

    Which puts me in the really frustrating position of having created a complete program which is totally and utterly finished except I don't know how to print a border character at that one corner position without it causing the screen to flip up and destroy my program!!!!

    Please tell me there is a fix??

  3. #3
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    I guess that you could use WriteConsoleOutputCharacter() instead of printf().
    Kurt

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    1,273
    I'm not sure there's a fix for this. Some people here have mentioned using Borland C++, not sure if it's IDE works with the dos console window though. You could could use 24 lines instead of 25 lines, or you could set the console window to be a bit larger. I don't know if there is a msdos / vesa compatible console for windows. You could install a version of dos into Virtual PC, which should work (you could then write directly to the video buffer memory).

  5. #5
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by rcgldr View Post
    you could then write directly to the video buffer memory.
    I think that's what WriteConsoleOutputCharacter() does.

    Quote Originally Posted by MSDN
    Copies a number of characters to consecutive cells of a console screen buffer, beginning at a specified location.
    Kurt

  6. #6
    Registered User
    Join Date
    Apr 2013
    Posts
    1,273
    Quote Originally Posted by ZuK View Post
    WriteConsoleOutputCharacter().
    I tried this on Windows XP and it worked.

    More info on "consoles" from msdn here.

    consoles.aspx
    Last edited by rcgldr; 05-18-2013 at 05:40 AM.

  7. #7
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    241
    Ok, thanks for that guys.

  8. #8
    Registered User
    Join Date
    Apr 2013
    Posts
    1,273
    Not a big deal, but I have my dos console window defaulted to 80 columns and 50 rows, I haven't found a console function that will reduce it to 80 x 25. The code works, but I have 25 extra lines in the window.

  9. #9
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    241
    I'm using a combination of Windows XP and the Codeblocks IDE with gcc and the code resizes the window ok.

    My actual program (version of "Game Of Life") uses a larger window.

    Now graced by shiny,sparkly border!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 01-07-2013, 09:53 AM
  2. Printing from an opened file character by character
    By SneakySnake in forum C Programming
    Replies: 1
    Last Post: 12-07-2012, 12:05 PM
  3. SDL Window opening with Console Window
    By carrotcake1029 in forum Windows Programming
    Replies: 2
    Last Post: 12-23-2008, 02:32 PM
  4. Printing In Console C++
    By LostNotFound in forum C++ Programming
    Replies: 1
    Last Post: 02-15-2003, 04:46 PM
  5. Trouble Printing ASCII Character
    By drdroid in forum C++ Programming
    Replies: 2
    Last Post: 04-27-2002, 08:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21