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.

Challenge: Fix the code

Challenge: Fix the code - C Tutorial

From the course: Debugging C Code

Start my 1-month free trial

Challenge: Fix the code

(upbeat electronic music) - [Instructor] The code presented as this challenge's exercise file initializes two character arrays and then prompts for input. The resulting string is then output. This seems rather straightforward, silly in fact. Here are the bash shell in Ubuntu Linux for Windows all built to code, so clan and the Wall switch for all the warnings and errors, and then the program file name. Now the code builds without any warnings or errors, no help there. And then to run it using the default output file name, and the output portrays the code's flaws. You see the duplicate, which contains periods used to initialize the buffer, as well as a second version of the string. Weird. Your task for this challenge is to fix the code. Use the GNU debugger, GDB, yes in text mode, in the bash shell, to examine the code as it runs. Look at variables, dump memory, and use the tools available to find where the bug occurs.…

Contents