C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-30-2010, 06:12 AM   #1
Registered User
 
Join Date: Jun 2010
Posts: 182
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:
Code:
//--------------------------------------------------------------------------------------------------
//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);

    return;

}
When I compile I get these errors:
Code:
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:
Code:
typedef struct _CHAR_INFO { // chi  
    union {                /* Unicode or ANSI character  */ 
        WCHAR UnicodeChar; 
        CHAR AsciiChar; 
    } Char; 
    WORD Attributes;       // text and background colors 
} CHAR_INFO, *PCHAR_INFO;
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.
frktons is offline   Reply With Quote
Old 07-30-2010, 08:47 AM   #2
and the hat of Destiny
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 22,695
Start with
Code:
CHAR_INFO array[10];  // pick your size
Then do
Code:
array[0].Char.AsciiChar = mystring[0];  // and the rest of them
array[0].Attributes = 0;  // RTM for RED, FLASH, whatever...
Finally,
Code:
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.

Salem is offline   Reply With Quote
Old 07-30-2010, 10:35 AM   #3
Registered User
 
Join Date: Jun 2010
Posts: 182
Thanks salem. This is a different solution, but it can be feasible.

I have the
Code:
AsciiChar
Attributes
In an array of characters source[4000] in this shape:
Code:
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:
Code:
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.
frktons is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with console program feso4 C++ Programming 3 10-22-2006 11:53 AM
Eeks! locating a the cursor in a console app is a real _bear(). Pete_2000 C Programming 12 05-06-2006 03:34 PM
Windows console problems tigs Windows Programming 2 03-14-2003 11:20 AM
Linux console window questions GaPe Linux Programming 1 12-28-2002 12:18 PM
Sprites In Console c++_n00b A Brief History of Cprogramming.com 4 04-13-2002 07:02 AM


All times are GMT -6. The time now is 08:26 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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