The role of function main()
In general,
small programs,
even if just written in a single file,
will have several functions.
We will no longer place all of our statements in the main() function.
main() should be constrained to:
- receive and check the program's command-line arguments,
- report errors detected with command-line arguments,
and then call exit(EXIT_FAILURE),
- call functions from main(),
typically passing information requested and provided by
the command-line arguments,
and
- finally call exit(EXIT_SUCCESS) if all went well.
And, in a forthcoming lecture, the following will make more sense:
- All error messages printed to the stderr stream.
- All 'normal' output printed to the stdout stream
(if not to a requested file).
CITS2002 Systems Programming, Lecture 4, p4, 31st July 2024.
|