The reason that
system("cd some_dir") doesn't work is because the
system call is spawning a new process (in this case a shell), so any changes made to that shell's environment (such as changing the current working directory) are lost when the sub-process exits. You end up creating a child process and sending
it to a new directory, where it expectedly dies/exits of natural causes and returns control back to you. You didn't move anywhere.