PWD in C

Tutor: None Selected Time limit: 3 Days

way to make pwd version in C. But not sure how to approach it in C. The idea is first, call lstat() on "." to find out the inode number of the current directory (the "st_ino" member of the struct stat).

Then I change our current directory to the parent directory, with chdir("..").

Then I want to read the parent directory with opendir()/readdir() (using "opendir(".")" because we've now cd'd there),I am mostly interested in the d_ino value in the struct returned by readdir(). I am looking for the original directory in the parent directory. When we find it, we print its name.

Then call chdir("..") again, and repeat until the inode number is 2, at which point you can print "and then we're at the root directory" (or some such similar message). The idea is great :) Any ideas? Thanks.

Nov 5th, 2013
int main()
//char buf[1024];

char * buf;
char * cwd;
buf = (char *)malloc(sizeof(char) * 1024);

if((cwd = getcwd(buf, sizeof(buf))) != NULL)
printf("pwd : %s\n", cwd);
perror("getcwd() error : ");
return 0;
But with pointer it shows following error

getcwd() error : : Numerical result out of range
Nov 6th, 2013

Nov 5th, 2013
Nov 5th, 2013
Oct 22nd, 2016
Mark as Final Answer
Unmark as Final Answer
Final Answer

Secure Information

Content will be erased after question is completed.

Final Answer