Skip to content

Instantly share code, notes, and snippets.

@calebreister
Last active August 29, 2015 13:56
Show Gist options
  • Save calebreister/9199796 to your computer and use it in GitHub Desktop.
Save calebreister/9199796 to your computer and use it in GitHub Desktop.
#ifdef WINDOWS
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif
int main()
{
char cCurrentPath[FILENAME_MAX];
if ( !GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
{
return 1;
}
cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; /* not really required */
printf("The current working directory is %s\n", cCurrentPath);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment