From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Challenge: Read and store filenames - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Challenge: Read and store filenames
(upbeat music) - [Instructor] This challenge is quite involved, but in the big picture you have three overall tasks: first prompt the user for a pathname, a directory to read; second, open that directory and read its full list of files; third, output that list to a file named filelist.txt. Here are some suggestions. Strip out the newline character from user input. Valid pathnames do not contain a newline character. Remember that the chdir function returns zero upon success. This result is how you can both change to a given directory and validate pathname input. Finally, the filelist.txt file must be created in the same directory as the program you create. So, if the program runs in one directory, that's the same directory in which the filelist.txt file must be created. This challenge could take up to 40 minutes to complete.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Reading from a file3m 25s
-
Writing to a file3m 24s
-
Working with raw data2m 53s
-
Using random file access2m 47s
-
Manipulating files2m 57s
-
Exploring the path2m 8s
-
Reading a directory2m 53s
-
Getting file information2m 46s
-
Using command line arguments2m 44s
-
Calling the operating system2m 46s
-
Challenge: Read and store filenames1m 6s
-
Solution: Read and store filenames2m 52s
-
-
-