A few days ago, my clearing screen function, that I never really edited during that time, started giving an error for no reason.
I searched on Google, and nobody has been having any trouble with it. I searched the function again in several websites (including this own's website version of it), they were all almost the same anyways. I deleted my function and just copy-pasted the original "cls" function from the internet, a few times, still the same error.
So I tested the EXACT SAME function in another program (something like test.cpp) and it worked without any problem, so it's my program's fault. But I tried finding the reason of this happening and it seems everything's in order.
The function is the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
void ClearScreen(){
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = { 0, 0 }; // home for the cursor
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
// Get the number of character cells in the current buffer.
if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
{
return;
}
dwConSize = csbi.dwSize.X * csbi.dwSize.Y; //THIS LINE GIVING AN ERROR
// Fill the entire screen with blanks.
if( !FillConsoleOutputCharacter( hConsole, // Handle to console screen buffer
(TCHAR) ' ', // Character to write to the buffer
dwConSize, // Number of cells to write
coordScreen, // Coordinates of first cell
&cCharsWritten ))// Receive number of characters written
{
return;
}
// Get the current text attribute.
if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
{
return;
}
// Set the buffer's attributes accordingly.
if( !FillConsoleOutputAttribute( hConsole, // Handle to console screen buffer
csbi.wAttributes, // Character attributes to use
dwConSize, // Number of cells to set attribute
coordScreen, // Coordinates of first cell
&cCharsWritten )) // Receive number of characters written
{
return;
}
// Put the cursor at its home coordinates.
SetConsoleCursorPosition( hConsole, coordScreen );
}
|
I get two errors in the value definition of dwConSize:
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
error: expected unqualified-id before numeric constant
error: expected ; before numeric constant |
I put the function prootype (
void ClearScreen();
) in a file called Functions.h in my program, and the whole function in a file called Functions.cpp. I'm using the lastest version of the CodeBlocks IDE and compiler.
Edit: I've been playing a little with it, and it seems the problem is the X or Y COORD values, as trying to declare any
COORD
variable in my code and trying to use
coordName.X
or
coordName.Y
gives me the exact same errors.