LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   about chdir() (https://www.linuxquestions.org/questions/programming-9/about-chdir-237710/)

feetyouwell 10-01-2004 07:09 PM

about chdir()
 
I just found out cd is embedded with the shell, not an actually command

I wrote the following code in my shell program, but it returns me to tell me the dir doesn't exist, what did I do wrong
Code:

char *pcd, *cd;
int i;
pcd = buf;          //buf is the shell cmd line input
if ((cd = strstr(pcd, "cd")) != NULL) {
                cd += 2;
                if ((i = chdir(cd)) !=0) {
                perror ("chdir");
                }
                exit(0);
        }


CroMagnon 10-01-2004 07:52 PM

Try trimming spaces off the front of the directory name.

feetyouwell 10-01-2004 10:14 PM

I got it, the problem isn't the white space, i think it is the '\n' char, it's giving a lot of troubles

CroMagnon 10-02-2004 12:26 PM

From other things you've posted, it seems as if you're writing a shell, or a shell go-between - you might want to look at the strtok() function to help with things like this.


All times are GMT -5. The time now is 05:42 PM.