...

View Full Version : C problem



Lippy
01-25-2005, 05:29 AM
Hey, what is the function to clear the command window in C from everything thats been printed in it?

Thanks for the help,
Lippy

Dr. Evil
01-25-2005, 01:24 PM
You can use the non-ANSI standard function clrscr(), but it would be better to make one yourself. Or, if you'd rather, here's a function I modified from someone else to do the same. You'd pass it the handle to the console output (ie. HANDLE console_out_h = GetStdHandle(STD_OUTPUT_HANDLE))


#include <windows.h>

int ClearScreen(HANDLE console_out)
{
DWORD writ, len;
CONSOLE_SCREEN_BUFFER_INFO console_buffer_info;
COORD start = {0, 0};

GetConsoleScreenBufferInfo(console_out, &console_buffer_info);
FillConsoleOutputCharacter(console_out, (TCHAR)32,
(console_buffer_info.dwSize.X * console_buffer_info.dwSize.Y), start,
&writ);

GetConsoleScreenBufferInfo(console_out, &console_buffer_info);
FillConsoleOutputAttribute(console_out, console_buffer_info.wAttributes,
(console_buffer_info.dwSize.X * console_buffer_info.dwSize.Y), start,
&writ);

SetConsoleCursorPosition(console_out, start);

return 0;
}

aman
01-25-2005, 05:38 PM
Something like that is probably the best way *if* you're using windows.

If you compiler has it..


#include <conio.h>

int main()
{
clrscr();

return 0;
}



A quick way I sometimes use is the system() command..


#include <stdlib.h>

int main()
{
system("cls"); // windows

system("clear"); // gnuc

return 0;
}

Lippy
01-26-2005, 04:39 AM
Thanks alot for the help... Thats exactly what I needed

Lippy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum