nld Manual

Sample nld and noft Session
nld Manual528272-001
A-4
Source Module MODULE1C
The wrap-up function displays the number of passengers on the bus at the last stop
and goes through the bus stop array, printing the number of people left at each stop.
The bus stop array is then freed.
Example A-6. Source Module MODULE1C With Edit Line Numbers
.1 #pragma nolist
1 #include <stdlibh>
1.001 #include <stdioh>
1.01 #pragma list
1.011 #include "globals.h"
1.1 #include "module1.h"
1.2 #include "util.h"
2
3 void initialize(long stops)
4 {
4.01 long counter;
4.02 long passenger_count;
4.1
5 bus_stop_array = (long *)malloc(stops*sizeof(long));
5.1 seed_random_number();
6 for (counter = 0; counter < stops; counter++)
6.01 {
6.02 passenger_count = 0x7F & rand();
6.03 while (passenger_count > BUS_STOP_CAPACITY)
6.04 passenger_count = 0x7F & rand();
6.05
6.1 bus_stop_array[counter] = passenger_count;
7 }
8 } /* initialize */
9
17 void wrapup(long stops)
18 {
19 long counter;
19.01
19.1 printf("Number of people on bus at last stop = %d.\n",
19.11 passengers_on_bus);
19.2 printf("\nPassengers remaining at each bus stop.\n");
19.3 printf("Bus Stop Passenger Count\n");
20 for (counter = 0; counter < stops; counter++)
20.1 {
20.2 printf("%4d %4d\n", (counter + 1), bus_stop_array[counter]);
20.3 }
20.4 free(bus_stop_array);
21
22
23 } /* wrapup */