Skip to content

Instantly share code, notes, and snippets.

@ardianta
Created January 2, 2020 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ardianta/8fbb5c227551f4e3152c5daa025cb6f0 to your computer and use it in GitHub Desktop.
Save ardianta/8fbb5c227551f4e3152c5daa025cb6f0 to your computer and use it in GitHub Desktop.
Clear Screen in C
#include <stdlib.h>
#include <stdio.h>
void clear_screen(){
#ifdef _WIN32
system("cls");
#elif defined(unix) || defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
system("clear");
//add some other OSes here if needed
#else
#error "OS not supported."
//you can also throw an exception indicating the function can't be used
#endif
}
int main()
{
clear_screen();
system("ls");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment