From the course: C: Data Structures, Pointers, and File Systems

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Exploring the path

Exploring the path - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

Exploring the path

- [Instructor] When a program runs, it has direct access to all the files in the same folder or directory. To work with other files, you must either construct the full or relative path to them or change to the given directory. First, it helps to know in which directory the program is running. In this exercise file, the get current working directory function at line 8 fetches a string representing the current working directory. This function is prototyped in the unistd header file included at line 2. The get current working directory function's two arguments are a character buffer, in which the path will be saved, and the size of that buffer. Build and run. And, of course, the output you see on your system will be different from what I see here. But on this system, this is the folder in which the program is running. When your program needs to operate in another directory, you use the chdir function, which is analogous to the chdir command in a Terminal window. As with the get current…

Contents