參考資訊:
https://stackoverflow.com/questions/2910377/get-home-directory-in-linux
main.c
#include <pwd.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> int main(int argc, char **argv) { const char *homedir = getenv("HOME"); printf("%s\n", homedir); return 0; }