I'm trying to use chdir()
function but can't work it out.
I'm reading from user and find out if he is using "cd". I always get an error. What am I doing wrong?
Code:
int * status=0;
char * buf = 0;
char arguments[2048];
buf = getcwd(buf,PATH_MAX);
printf("%s >",buf);
fgets(arguments,2048,stdin);
if( strncmp(arguments,"quit",4)==0 ){
printf("Exit...\n");
break;
}
else if(strncmp(arguments,"cd",2)==0 ){
int ret;
printf("\nGOT = %s\n",(arguments+2));
ret = chdir ((arguments+2));
if(ret!=0){
perror("Error:");
}
}