Getting home directory in Mac OS X using C language
问题 How can I get the path of home directory in Mac OS X using C language in XCode editor. 回答1: #include <stdlib.h> #include <stdio.h> int main(void) { const char *homeDir = getenv("HOME"); if (homeDir) printf("Home directory is %s\n", homeDir); else printf("Couldn't figure it out.\n"); return 0; } 回答2: This should work under Linux, Unix and OS X, for Windows you need to make a slight modification. #include <stdlib.h> #include <stdio.h> #include <pwd.h> #include <unistd.h> int main(void) { const