From the course: Debugging C Code

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Fix the code

Solution: Fix the code - C Tutorial

From the course: Debugging C Code

Start my 1-month free trial

Solution: Fix the code

(upbeat music) - [Instructor] I fired up the new debugger and loaded the program for this challenges exercise file. The buffers are filled with periods starting at line 12. Then the first buffer is copied to the second one at the for loop here at line 25. But what I'm curious about is the duplicate buffer, and how it gets all crazy. So, I'll set a breakpoint after the string is copied at line 29. And run to that point, (keyboard typing) work the code. And now let's look at the buffers. So we'll print the original. And there's this string terminated by the null character, and then a bunch of dots. And now let's print the duplicate. And you see the string and a bunch of dots, but what's missing is the null character. There's no null character there. That explains a lot. Let's dump memory just to be sure (keyboard typing) And do it from where the duplicate string is created. (keyboard typing) This memory dump…

Contents