Debugging in generalBasic method of all debugging:. Know what your program is supposed to do. Detect when it doesn't. Fix it.A tempting mistake is to skip step 1, and just try randomly tweaking things until the program works. Better is to see what the program is doing internally, so you can see exactly where and when it is going wrong. A second temptation is to attempt to intuit where things are going wrong by staring at the code or the program's output. Avoid this temptation as well: let the computer tell you what it is really doing inside your program instead of guessing.
Gdb Run Program
AssertionsEvery non-trivial C program should include, which gives you the assert macro (see Appendix B6). The assert macro tests if a condition is true and halts your program with an error message if it isn't.