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

Challenge: Read and store filenames - C Tutorial

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

Start my 1-month free trial

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.

Contents