
Sample nld and noft Session
nld and noft Manual — 520384-003
A- 3
Source Module MAINC
Source Module MAINC
Source module MAINC has the
main
function. The
main
function calls the
initialize
function to allocate the bus stop array and to set a random number of
passengers in each cell of the array. The
main
function then loops, incrementing a
counter until the counter is greater then the number of bus stops. For each iteration
(bus stop),
main
calls the
delete_passengers
and
add_passengers
functions. At
the completion of the loop,
main
calls the
wrap-up
function, which displays the
number of people on the bus and the number of people left at each bus stop.
Source Module MODULE1C
Source module MODULE1C contains the
initialize
and
wrap-up
functions. The
initialize
function uses the
malloc
function to allocate the bus stop array. Next,
the
initialize
function calls the
seed_random_number
function in the user library
to reduce the chance that the same random numbers will come up each time the
program runs. The
initialize
function sets each element of the bus stop array to a
random number from 0 through 127. The random numbers are the results of the
rand
function bitwise-ANDed to the hexadecimal number 0x7F. If a random number (which
represents the number of people at a bus stop) is greater than the DEFINE for the bus
stop capacity, the
rand
function is called until it returns a value in the desired range,
which is assigned to an element of the bus stop array.
Example A-4. Header File UTILH With Edit Line Number
1 void seed_random_number(void);
Example A-5. Source Module MAINC With Edit Line Numbers
.01 #pragma nolist
.1 #include <stdlib.h>
1 #pragma list
1.001 #include "globals.h"
1.1 #include "module1.h"
1.2 #include "module2.h"
2
2.1 long *bus_stop_array;
2.2 long passengers_on_bus = 0;
3
4 void main(void)
5 {
5.1 long bus_stops = MAXSTOPS;
5.2 long counter;
5.3
6 initialize (bus_stops);
7 for (counter = 0; counter < bus_stops; +)
8 {
8.001 if (passengers_on_bus > 0)
8.01 delete_passengers(counter);
8.1 add_passengers(counter);
9 }
10 wrapup(bus_stops);
11 exit (EXIT_SUCCESS);
12
13 } /* main */
Summary of Contents for nld
Page 12: ...Contents nld and noft Manual 520384 003 x ...
Page 16: ...What s New in This Manual nld and noft Manual 520384 003 xiv Miscellaneous ...
Page 22: ...About This Manual nld and noft Manual 520384 003 xx Change Bar Notation ...
Page 28: ...Introduction to the Utilities nld and noft Manual 520384 003 1 6 strip ...
Page 60: ...nld Utility nld and noft Manual 520384 003 2 32 Declaration and Definition ...
Page 78: ...nld Options nld and noft Manual 520384 003 3 18 y ...
Page 90: ...noft Utility nld and noft Manual 520384 003 4 12 Debugging With noft ...
Page 150: ...strip Utility nld and noft Manual 520384 003 7 2 ...
Page 242: ...nld Diagnostic Messages nld and noft Manual 520384 003 10 82 Informational Messages ...
Page 278: ...noft Diagnostic Messages nld and noft Manual 520384 003 11 36 Syntax Errors ...
Page 286: ...ar Diagnostic Messages nld and noft Manual 520384 003 12 8 ...
Page 314: ...Sample nld and noft Session nld and noft Manual 520384 003 A 28 LISTSRLFIXUPS ...
Page 330: ...Index nld and noft Manual 520384 003 Index 10 Special Characters ...