chdir() to home directory
问题 I am using the chdir() C function to allow a user to change directory. The function however, doesn't recognize '~'. Do I need to do any explicit conversion, so chdir doesn't recognize what ~ means? Because mine isn't working. Or am I doing something wrong? 回答1: Tilde expansion is handled by the shell, not by a system call. You could use getenv() to read the environment variable HOME and then use that as the argument to chdir() . There are system calls to get this information that may be more