I'm trying to write a simple C++ program to execute Linux commands. I'm stuck at changing the directories (commands like
system("echo -n '1. Current Directory is '; pwd");
The reason is that
chdir affects only the calling process (which would be your C program) not the parent process. Each process has its own current directory.
You need to read Advanced Linux Programming.
Perhaps you want to call
chdir directly inside your C program. This will affect the current process and all future child processes (including those started with
popen library functions inside your C code) till their termination or some further call to
chdir. But it won't affect the shell in your terminal (where you started your C program).