Thread: writing to the console

  1. #1
    Registered User
    Join Date
    Jun 2010

    writing to the console

    Hello everybody.
    I'm trying to write to the console with WriteConsoleOutput, but I get some
    errors during compilation.
    The code I've written so far:
    //Display a 80cols  x 25 rows fixed size console
    void  DisplayCon(char target[]){
        COORD bufferSize = {80, 25};
        COORD TopLeft = {0,0};
        SMALL_RECT Out_buf; 
        Out_buf.Left = 0;
        Out_buf.Top = 0;
        Out_buf.Right = 24;
        Out_buf.Bottom = 79;
        WriteConsoleOutput(wHnd, target, bufferSize, TopLeft, Out_buf);
    When I compile I get these errors:
    Type error in argument 2 to 'function'; expected 'const CHAR_INFO *' but found 'char *'.
    Type error in argument 5 to 'function'; expected 'PSMALL_RECT' but found 'SMALL_RECT'.
    regarding the WriteConsoleOutput call.

    What am I missing?

    The array I'm using to store the data to be displayed: target[] should
    be a CHAR_INFO structure. If I want to use the same area using union,
    the same that I'm using for array target[], how should I define the structure?

    CHAR_INFO has already a union inside:
    typedef struct _CHAR_INFO { // chi  
        union {                /* Unicode or ANSI character  */ 
            WCHAR UnicodeChar; 
            CHAR AsciiChar; 
        } Char; 
        WORD Attributes;       // text and background colors 
    I am not able to figure how should I declare the structure with a union to
    have the same area of 8000 bytes usable in both array mode and struct mode.

    Thanks for any help you can give me.
    Last edited by frktons; 07-30-2010 at 06:33 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Start with
    CHAR_INFO array[10];  // pick your size
    Then do
    array[0].Char.AsciiChar = mystring[0];  // and the rest of them
    array[0].Attributes = 0;  // RTM for RED, FLASH, whatever...
    WriteConsoleOutput(wHnd, array, bufferSize, TopLeft, &Out_buf);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Thanks salem. This is a different solution, but it can be feasible.

    I have the
    In an array of characters source[4000] in this shape:
    first character:
    source[0] contains the AsciiChar
    source[1] contains the Attributes
    second character:
    source[2] contains the AsciiChar
    source[3] contains the Attributes
    and so on.
    If I assign the values:
    array[0].Char.AsciiChar = source[0];  
    array[0].Attributes =source[1];
    and so on
    I leave the remaining 2 bytes of the structure uninitialized, but I want that they
    contain both a space [ASCII 32].
    So I need to put some value also in the remaining 2 bytes of the
    structure. How do I access them?
    Last edited by frktons; 07-30-2010 at 10:49 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with console program
    By feso4 in forum C++ Programming
    Replies: 3
    Last Post: 10-22-2006, 11:53 AM
  2. Replies: 12
    Last Post: 05-06-2006, 03:34 PM
  3. Windows console problems
    By tigs in forum Windows Programming
    Replies: 2
    Last Post: 03-14-2003, 11:20 AM
  4. Linux console window questions
    By GaPe in forum Linux Programming
    Replies: 1
    Last Post: 12-28-2002, 12:18 PM
  5. Sprites In Console
    By c++_n00b in forum A Brief History of
    Replies: 4
    Last Post: 04-13-2002, 07:02 AM