File vs keyboard/screen input-output functions
File
Stdio (i.e. the keyboard and screen)
ch=getc(fp)
ch=getchar()
putc(ch,fp)
putchar()
fprintf()
printf()
fscanf()
scanf()
fgets(string, length,fp)
gets()
fputs(string,fp)
puts()
where:
FILE *fp
char ch
char *string
General causes of bugs
Failure to initialize
Array bounds overflow -- this has very unpredictable results (including crashing the machine)
Failure to anticipate a logical combination on a branch. This is particularly problematic when you are dealing with input files
"Off-by-one" errors -- program works except for the first or last iteration
Algorithm/equation is incorrect in the first place
Copying some code and forgetting to change a variable name
Mixing local and global variables; side-effects from procedures. More generally, believing a variable has a different value than it has.
General advice on debugging:
Compartmentalize: make sure your procedures work before combining them into programs.
Test everything as you go along, and use a debugger
Insert print statements everywhere to verify the values of variables when you don't know what is going on (or use a debugger)
Read the code very, very carefully
Priorities:
Make it run
-- eliminate syntactic errors and anything else that crashes the program
Make it right
-- be sure the program is doing what you want it to do
Make it rapid
-- optimize the code if necessary (for most applications you will write, this won't be necessary)