C can be as structured or as unstructured as you like, but it's best
to follow a few simple rules:
- Stick to one statement per line.
- Indent appropriately to show nested logic.
- Use descriptive variable and function names.
- Break large tasks into smaller tasks using functions.
- Use comments (delimited by /* and */) effectively.
- Avoid excessive use of global variables (in fact, avoid them
altogether if possible!).
- Always use assert()s or some other kind of error
- Reduce argument lists by using suitable structs where
- Define obscure numerical constants at the beginning of a source
file with #define macros or const statements; this
makes the code easier to understand and change later on.
- Consider using enums to give descriptive names to simple
integer flag values.
Note that in C all variables and functions must be defined before they
are used. This is a good thing.