If your code compiles, but doesn't run as well as you expected, try using "lint" to help you clean up your code. Lint, according to its manual page:
Lint attempts to detect features of the C program files which are
likely to be bugs, or non-portable, or wasteful. It also checks the
type usage of the program more strictly than the compilers. Among the
things which are currently found are unreachable statements, loops not
entered at the top, automatic variables declared and not used, and
logical expressions whose value is constant. Moreover, the usage of
functions is checked to find functions which return values in some
places and not in others, functions called with varying numbers of
arguments, and functions whose values are not used or whose values
are used but none returned.
To use lint, type:
Many of the things lint warns about can also be found by using the -pedantic option to gcc.