How to clear the console screen in C

3 Answers

0 votes
#include <stdio.h>
#include <stdlib.h>
 
// system("clear") — Linux / macOS
 
int main() {
    printf("Have a nice day");
    
    // system("clear");
    printf("\e[1;1H\e[2J");
     
    return 0;
}
 
  
/*
run:
  
 
  
*/

 



answered Jun 11, 2015 by avibootz
edited 28 minutes ago by avibootz
0 votes
#include <stdio.h>
#include <stdlib.h>

// system("cls") — Windows

int main() {
    printf("Have a nice day");
    
    system("cls");
    
    
    return 0;
}

 
/*
run:
 

 
*/

 



answered 1 hour ago by avibootz
edited 30 minutes ago by avibootz
0 votes
#include <stdio.h>
#include <stdlib.h>

// Cross-platform C code to clear the console

void clearConsole() {
#ifdef _WIN32
    system("cls");   // Windows
#else
    system("clear"); // Linux / macOS / Unix
#endif
}

int main() {
    printf("Have a nice day\n");

    clearConsole();

    printf("Screen cleared!\n");
    
    return 0;
}


  
/*
run:
  
 
  
*/

 



answered 24 minutes ago by avibootz
...