Source Module Mainc; Source Module Module1C; Example A-4. Header File Utilh With Edit Line Number - HP nld Manual

Table of Contents

Advertisement

Sample nld and noft Session

Example A-4. Header File UTILH With Edit Line Number

1
void seed_random_number(void);

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.
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
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; counter++)
8
{
8.001
if (passengers_on_bus > 0)
8.01
8.1
add_passengers(counter);
9
}
10
wrapup(bus_stops);
11
exit (EXIT_SUCCESS);
12
13
} /* main */

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.
passengers_on_bus = 0;
delete_passengers(counter);
nld and noft Manual—520384-003
A- 3
Source Module MAINC

Advertisement

Table of Contents
loading

This manual is also suitable for:

Noft

Table of Contents