UMBC CS 201, Fall 02
UMBC CMSC 201 Fall '02 CSEE | 201 | 201 F'02 | lectures | news | help

OK, It Compiles, Now What?

You know by now that getting your code to compile is less than half the battle. If your program is acting funny, there are a few things you can do. One is to use probes (printf statements).

Probes - printf() statements

Lots and lots of printf() statements. Print out every variable you pass in to a function every variable that changes, and every variable that comes out. Print out your constants, and the result of every computation. Then when you run your program, look at all the values of all the variables and see if you can figure out what's going wrong.

Statements like

create a much clearer picture of what's going on than

Because output to stdout is buffered, printf() statements must contain a newline character or they will not always give you an accurate picture of your program execution if the program stops suddenly, as in a segmentation fault or bus error.

CSEE | 201 | 201 F'02 | lectures | news | help

Monday, 11-Nov-2002 17:40:25 EST