Skip to content

Instantly share code, notes, and snippets.

@stpettersens
Created November 19, 2010 21:33
Show Gist options
  • Save stpettersens/707228 to your computer and use it in GitHub Desktop.
Save stpettersens/707228 to your computer and use it in GitHub Desktop.
Cross-platform functions
/*
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