LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-01-2004, 07:09 PM   #1
feetyouwell
Member
 
Registered: Dec 2003
Location: NC, US
Distribution: Novell Linux Eval (2.6.5)
Posts: 240

Rep: Reputation: 30
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);
	}

Last edited by feetyouwell; 10-01-2004 at 07:10 PM.
 
Old 10-01-2004, 07:52 PM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Try trimming spaces off the front of the directory name.
 
Old 10-01-2004, 10:14 PM   #3
feetyouwell
Member
 
Registered: Dec 2003
Location: NC, US
Distribution: Novell Linux Eval (2.6.5)
Posts: 240

Original Poster
Rep: Reputation: 30
I got it, the problem isn't the white space, i think it is the '\n' char, it's giving a lot of troubles
 
Old 10-02-2004, 12:26 PM   #4
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
chdir oldstinkyfish Linux - Software 3 11-14-2004 03:58 AM
smbd/service.c:set_current_service(56) chdir failed errors Medievalist Linux - Networking 0 09-02-2004 12:03 PM
Wine: permission denied to chdir Micro420 Linux - Software 1 11-16-2003 12:06 AM
chdir problem Abe_the_Man Linux - Software 4 08-19-2003 11:39 PM
Unicode chdir sourceman Programming 0 11-04-2002 01:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration