Created
January 2, 2020 01:03
-
-
Save ardianta/8fbb5c227551f4e3152c5daa025cb6f0 to your computer and use it in GitHub Desktop.
Clear Screen in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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