Click to See Complete Forum and Search --> : clrscr ( ) function


John Shibley
April 4th, 1999, 02:35 PM
I'm writing an app in console mode using Visual C++ 4.0 and after compiling, I get the following error messages:

Myfile.obj:error LNK2001:unresolved external symbol "void_cdecl slrscr(void)"(?clrscr@@YAXXZ)

Myfile.exe:fatal error LNK1120: 1 unresolved externals

Can anybody help me?

Daniel Levine
April 4th, 1999, 08:50 PM
Hi,

You are getting this message because the function clrscr() does not exist.

You can use the following code to clear the screen:

Note: This code is from MSDN, so it should work. If not, complain to MS.

// Code starts here

/* Standard error macro for reporting API errors */
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \
on line %d\n", __FILE__, GetLastError(), api, __LINE__);}

void cls( HANDLE hConsole )
{
COORD coordScreen = { 0, 0 }; /* here's where we'll home the
cursor */
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize; /* number of character cells in
the current buffer */

/* get the number of character cells in the current buffer */

bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "GetConsoleScreenBufferInfo" );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

/* fill the entire screen with blanks */

bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputCharacter" );

/* get the current text attribute */

bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "ConsoleScreenBufferInfo" );

/* now set the buffer's attributes accordingly */

bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputAttribute" );

/* put the cursor at (0, 0) */

bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
PERR( bSuccess, "SetConsoleCursorPosition" );
return;
}

// Code Ends Here

I hope this helps.

Daniel.

Masaaki
April 4th, 1999, 10:12 PM
Hi.

clrscr() surely exists.
You need the header file - conio.h

#include <conio.h> //non-standard header file needed
//for use of clear screen function clrscr.

However, even though you type this header file on your project and
you get error message, VC++ seems not to support this function.
Turbo C++ supports this.(my school project two years ago)

Hope for help.
-Masaaki Onishi-