Created
November 19, 2010 21:33
-
-
Save stpettersens/707228 to your computer and use it in GitHub Desktop.
Cross-platform functions
This file contains 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
/* | |
Cross-platform header | |
for functions that need to work on | |
more than just Windows | |
*/ | |
#include <stdlib.h> | |
#ifdef _WIN32 | |
#include <windows.h> | |
#else | |
#include <unistd.h> | |
#endif | |
void xsleep(int ms); | |
void xcls(void); | |
void xsleep(int ms) { | |
#ifdef _WIN32 | |
Sleep(ms); | |
#else | |
sleep(ms / 1000); // sleep takes s rather than ms | |
#endif | |
} | |
void xcls(void) { | |
#ifdef _WIN32 | |
system("cls"); // Windows is cls | |
#else | |
system("clear"); // Unix-like is clear | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment