From the course: Debugging C Code

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Challenge: Find the bug

Challenge: Find the bug - C Tutorial

From the course: Debugging C Code

Challenge: Find the bug

(upbeat music) - [Instructor] Here's source code for a program that extracts a file name from the end of a path name. Line 35 lists six path names in an array. Some are appended with a file name, others are not. These strings are passed to the file name function, which returns a pointer to the file name portion of the string. Build and run. It looks like the code runs fine, but there's a problem in the output. The file name is extracted, but with the leading separator, the slash character here and here. Path names without a file name show only the separator, and not an error message, which is what's coded in the function. It's possible to fix this issue without using a debugger, which is how I originally did it, but your task is more specific. Use the Codespaces debugger to examine the program. Step through the file name function to observe how the file name is extracted from the rest of the path name string. Use the tools available to track what's going on and to see where you can…

Contents