outputting multiple lines to the windows console is useless. It just adds blank lines to it. unfortunately, the path refers to specific windows and includes either conio.h (and clrscr () may not exist, this is not a standard header) or the Win API method
#include <windows.h> void ClearScreen() { HANDLE hStdOut; CONSOLE_SCREEN_BUFFER_INFO csbi; DWORD count; DWORD cellCount; COORD homeCoords = { 0, 0 }; hStdOut = GetStdHandle( STD_OUTPUT_HANDLE ); if (hStdOut == INVALID_HANDLE_VALUE) return; /* Get the number of cells in the current buffer */ if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return; cellCount = csbi.dwSize.X *csbi.dwSize.Y; /* Fill the entire buffer with spaces */ if (!FillConsoleOutputCharacter( hStdOut, (TCHAR) ' ', cellCount, homeCoords, &count )) return; /* Fill the entire buffer with the current colors and attributes */ if (!FillConsoleOutputAttribute( hStdOut, csbi.wAttributes, cellCount, homeCoords, &count )) return; /* Move the cursor home */ SetConsoleCursorPosition( hStdOut, homeCoords ); }
For a POSIX system, this is simpler; you can use ncurses or terminal functions
#include <unistd.h> #include <term.h> void ClearScreen() { if (!cur_term) { int result; setupterm( NULL, STDOUT_FILENO, &result ); if (result <= 0) return; } putp( tigetstr( "clear" ) ); }
Swift - Friday Pie Sep 29 '16 at 6:31 2016-09-29 06:31
source share