From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Debugging your code - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Debugging your code
- [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. Another message you can…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Solving math puzzles3m 32s
-
(Locked)
Creating random numbers3m 42s
-
(Locked)
Working with time functions3m 54s
-
(Locked)
Sorting data4m 8s
-
(Locked)
Debugging your code2m
-
(Locked)
Using a debugger4m 53s
-
(Locked)
Writing your own header file2m 53s
-
(Locked)
Mixing multiple source code files4m
-
(Locked)
Challenge: Lotto simulation1m 18s
-
(Locked)
Solution: Lotto simulation2m 29s
-
(Locked)
-