Join Dan Gookin for an in-depth discussion in this video Solution: Read and store filenames, part of C: Data Structures, Pointers, and File Systems.
(upbeat music) … - [Instructor] This type of challenge … shows that it can be easy to do small things … such as read a directory, … but when you start combining these tasks … into a larger project, the small things build … into a ziggurat of complexity. … Many different solutions are possible, of course, … for this challenge, but here's what I did, … broken into distinct parts. … The first thing this code does … is to open and create the output file at line 19. … When opened at this point, … the file is created in the program's directory, … which is what I wanted. … The first task assigned at line 27 … is to fetch and massage user input. … I use the fgets function at line 28, … but it appends a new line to input, … so the for loop at line 30 removes the new line … and replaces it with a null character, … effectively capping the string. … The next assigned task is to change to the path … that was input. … The chdir function at line 40 accomplishes this task. … If not, variable r does not equal zero. …
- 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.