code that reads commands from the standard i/p and executes the commands

Hello all,
i've written a small piece of code that will read commands from standard input and executes the commands.
Its working fine and is execting the commands well. Accepting arguments too. e.g
#mkdir <name of the directory>

The problem is that its not letting me change the directory i.e pwd is remaining the same.
what changes should be made in it to let it change the directories too.

#include <stdio.h>
#include <string.h>
#define MAXLINE 50

int main(void)
{
        char buf[MAXLINE];

        printf("%% ");
        while (fgets(buf, MAXLINE, stdin) != NULL)
        {
                buf[strlen(buf) -1] = 0;
                system(buf);
                printf("%% ");
        }
}

regards

I don't think you have fully understood what your own code is doing, with respect to the context in which it is executing commands relative to the shell in which it is invoked.

sorry to say that i'm still not clear...

I'm saying this in simplistic terms but here is what happens in terms of processes:

   your shell
       +
       |
       +------Your application
                         +
                         |
                         +-------The command your program runs

If you make a change in the bootom node in this list it has no effect on the ones above it. You cannot chdir in the parent from a within a child.

okay...

thanks.