You can use a few tricks to help track down bugs or other programs in your code. Use printf() statements to output variable values as the code runs or to flag the code's progress. Write notes to yourself in the comments so that you can resolve issues later. Talk through your code, explaining it out loud, which also helps find bugs and flaws in program flow or logic.
- [Instructor] When I'm at my wits' end … and I just can't figure out what's wrong with my code, … I use a few simple tricks to examine … the running code and fix the bugs. … These including outputting values as the program runs, … adding text flags at various points in the code, … writing myself notes in the comments, … and reading the code aloud. … First, you can track values throughout your code … by using temporary printf statements. … Output the value of a variable, for example, … before and after a function call … to ensure that the result is what you believe. … For pointers, remember that you can use the %p placeholder … to output an address. … Check that pointer's value to ensure that … it's being adjusted or saved in the way you want. … Use the __LINE__ preprocessor directive … to output specific line numbers in the source code. … This directive uses two underscores … on either side of the word LINE, all caps. … For example, this printf statement would tell me … where a problem may be occurring. …
- Working with arrays
- Building a structure
- Creating an array of structures
- Testing characters
- Working with strings in C
- Using pointers to manipulate data
- Manipulating files
- Using command-line arguments
- Working with time functions
Skill Level Intermediate
1. Arrays and Structures
2. Characters and Strings
4. Files and the Operating System
5. The Interesting and Extraordinary
Next steps1m 52s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.