How to debug a program? Can anyone give some tips to debug a program in C?
As of my knowledge here I am providing you some tips for debugging your c program
1. Assume nothing. Do not assume that a variable has the correct value, even if
we see that the variable is assigned a value.
Print the value of the variable in the down time.
Elsewhere in the program cannot be sacked.
2. When the value of a variable to something unexpected, check the logical tests to see if they have inadvertently put a value instead of tested.
3. Take a break. When you work on something else for a while, usually suddenly you will realize the cause of origin.
4. If the fault is not in the code section that was originally suspected, which is somewhere otherwise.
Do not fall into the trap of thinking, "Error cannot be in this part code, because I checked.
5. Fix all compiler warnings. Set the alert level as high as possible.
If you write Windows programs, use strict to ensure maximum
6. Pointers cause most problems. Array-held replace almost many problems. Strings are arrays. In most C compilers, all detected at limits are exceeded chain.
If the chain is on the stack, when its limits are exceeded (as it is an automatic variable), the program will probably do some strange things.
7. Backup of your disk. One of my first C programs quickly broke my record.
The one blessing is that I did not have a backup program that made the
the dirty work was done!
8. Sometimes there are compilation errors, but generally not the reason the program fails.
9. Another look at its programming code C.
10. When all else fails, rewrite the code to work differently.
You are not guaranteed a perfect program, just because you avoid these common elements
The most common error is the error the program simple logic.
The program does work as you think.
The program is syntactically correct and has not programming errors, but their logic is incorrect.
With hard work, a debugger, and patience, you can follow the progress of the program.
Finally, one can find the point where results are not what they expected, and perhaps the error.