Chapter 5 Preparing and Running a Complete C Program
Chapter 5 Preparing and Running a Complete C Program
Objectives
To plan, write and execute of a complete C
program.
To detect and correct the different types of
errors that can occur in improperly written
programs.
PLANNING A C PROGRAM
It is essential that the overall program strategy be
completely mapped out before any of the detailed
programming actually begins.
Concentrate on the general program logic, without
being concerned with the syntactic details of the
actual instructions.
Once the overall program strategy has been clearly
established, the details associated with the
individual program statements can be considered.
This approach is generally referred to as “top-down”
programming.
The resulting outline is usually referred to as
pseudocode.
Detailed version of the outline
Bottom-UP
Another method that is sometimes used when planning a C
program is the "bottom-up" approach.
This method may be useful for programs that make use of
self-contained program modules (e.g., user-defined
functions).
The bottom-up approach involves the detailed development
of these program modules early in the planning process.
The overall program development is then based upon the
known characteristics of these available program modules.
In practice we often use both approaches: top-down for the
overall program planning, bottom-up in developing
individual modules before the main part of the program, and
top-down with respect to the development of each individual
module.
WRITING A C PROGRAM
Once an overall program strategy has been
formulated and a program outline has been
written, attention canbe given to the detailed
development of a working C program.
At this point the emphasis becomes one of
translating each step of the program outline
(or each portion of the pseudocode) into one
or more equivalent C instructions.
This should be a straightforward activity
provided the overall program strategy has
been thought through carefully and in enough
detail.
Contd…
Attention should also be given to including
certain additional features that will improve
the readability of the program and its
resulting output.
These features include the logical sequencing
of the statements, the use of indentation and
whitespace, the inclusion of comments and
the generation of clearly labeled output.
A well written program in C