To discover which directory has a program running, use the getcwd() function. The chdir() function changes to the named path. Though a program may change directories as it executes, when the program is done, it returns to the directory in which it was started.
- [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. …
- Working with arrays
- Building a structure
- Creating an array of structures
- Testing characters
- Working with strings in C
- Using pointers to manipulate data
- Manipulating files
- Using command-line arguments
- Working with time functions
Skill Level Intermediate
1. Arrays and Structures
2. Characters and Strings
4. Files and the Operating System
5. The Interesting and Extraordinary
Next steps1m 52s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.