chdir and getcwd system calls

int main()
    char *buf,*ch;

    ch=”/home/karthic/codes”;//replace this with a valid path on your system
    chdir(ch);//changing the current directory
    buf=getcwd(buf,120);//getcwd is the system call which writes the current path into the string
    /*the second argument to the call is the no.of.bytes available in the string ,
    which indicates the hat is to be written into the string */

    printf(“\nThe current working directory is :%s “,buf);
    return 0;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s