Okay, this is kind of a newbie question, and I understand that the function parameters I gave for the function in question are probably horribly off, but here's what I'm trying to do:
I've got an 80x25 2D array of CHAR_INFO's (buffer) that will be printed to the console screen every iteration of the infinite loop. Because the buffer will be constantly changing (its a nethack like game), I want to change the array every loop.
I could easily just integrate the loop into the main function, but for the sake of learning and organization, I wanted to split it off into its own function WriteBuffer(); I've been looking everywhere on how I can pass the 2D CHAR_INFO array into the function by reference so I can edit it, but nothing seems to work. Please don't tell me to use vectors or anything, I'd like to work with what I've got here.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
#define SCREEN_WIDTH 80
#define SCREEN_HEIGHT 25
using namespace std;
void WriteBuffer(CHAR_INFO **bufferp[][SCREEN_WIDTH]);
int main()
{
//Initialize screen buffer and cursor
HANDLE hConsoleOutput( GetStdHandle(STD_OUTPUT_HANDLE) );
COORD dwBufferSize = { SCREEN_WIDTH,SCREEN_HEIGHT };
COORD dwBufferCoord = { 0, 0 };
SMALL_RECT rcRegion = { 0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1 };
CHAR_INFO buffer[SCREEN_HEIGHT][SCREEN_WIDTH];
CONSOLE_CURSOR_INFO lpConsoleCursorInfo = { 1, false };
SetConsoleCursorInfo(hConsoleOutput, &lpConsoleCursorInfo);
//characters
char characters[3];
characters[0] = static_cast<char>(177);
characters[1] = static_cast<char>(177);
characters[2] = static_cast<char>(177);
characters[3] = static_cast<char>(177);
//colors
ULONG colors[3];
colors[0] = 0x0A;
colors[1] = 0x0B;
colors[2] = 0x0C;
colors[3] = 0x0D;
//begin infinite loop
while (1)
{
ReadConsoleOutput( hConsoleOutput, (CHAR_INFO *)buffer, dwBufferSize,dwBufferCoord, &rcRegion );
WriteConsoleOutput( hConsoleOutput, (CHAR_INFO *)buffer, dwBufferSize,dwBufferCoord, &rcRegion );
Sleep(100);
}
}
void WriteBuffer(CHAR_INFO **bufferp[][SCREEN_WIDTH])
{
int x, y, i = 0;
while(y < SCREEN_HEIGHT)
{
while(x < SCREEN_WIDTH)
{
bufferp[y][x].Char.AsciiChar = characters[i];
bufferp[y][x].Attributes = colors[i];
x++;
}
x = 0;
y++;
}
}