Advertisement
MenddGabriel

Clear screen - Windows

Oct 20th, 2021
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <windows.h>
  4.  
  5. void clear();
  6.  
  7. int main(){
  8.    
  9.     char string[100];
  10.    
  11.     printf( "Para limpar:\t:c\n"
  12.                 "Para sair:\t:q\n\n");
  13.    
  14.     do{
  15.         memset(string, '\0', 100); /* Preenche a string com \0 */
  16.        
  17.         scanf( " %99[^\n]s", string); /* Le a string ate uma nova linha */
  18.        
  19.         if(string[0] == ':' && string[1] == 'c'){
  20.             clear();
  21.             printf( "Para limpar:\t:c\n"
  22.                 "Para sair:\t:q\n\n");
  23.         }
  24.        
  25.     }while((string[0] == ':' && string[1] == 'q') != 1 );
  26.    
  27.     return 0;
  28. }
  29.  
  30.  
  31. void clear() {
  32.  
  33.     DWORD n;                        /* Número de caracteres escritos */
  34.     DWORD size;                     /* número de caracteres visíveis */
  35.     COORD coord = {0, 0};           /* Posição superior esquerda da tela */
  36.     CONSOLE_SCREEN_BUFFER_INFO csbi;
  37.    
  38.     /* Obter um identificador para o console */
  39.     HANDLE h = GetStdHandle (STD_OUTPUT_HANDLE);
  40.    
  41.     GetConsoleScreenBufferInfo (h, & csbi);
  42.  
  43.     /* Encontre o número de caracteres a serem sobrescritos */
  44.     size = csbi.dwSize.X * csbi.dwSize.Y;
  45.    
  46.     /* Sobrescrever o buffer de tela com espaços em branco */
  47.     FillConsoleOutputCharacter (h, TEXT (' '), size, coord, & n);
  48.     GetConsoleScreenBufferInfo (h, & csbi);
  49.     FillConsoleOutputAttribute (h, csbi.wAttributes, size, coord, & n);
  50.    
  51.     /* Redefine o cursor para a posição superior esquerda */
  52.     SetConsoleCursorPosition (h, coord);
  53.    
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement