exch - interactively inspect and change values of elements in an
exch (ptr, nelt)
int *ptr, nelt;
allows the user to inspect and change the value of any one of
integers in the array beginning at
It first prompts the user with the string "element #" printed to the
standard output (usually the console terminal). THe user should enter
an integer from 0 to
-1 followed by a CR (pressing the
key) to specify which element in the array to examine. If an illegal
element number is entered, an error message is printed and the prompt
is repeated. When
has received a valid element number it prints the value of that
element, requests a "newvalue?", and waits for the user to enter
either an optionally signed digit string followed by a CR or simply a
CR. If an integer is entered it replaces the old value of the
current array element; if only a CR is entered,
prompts for the next element #. However, if anything other than a
digit string or a CR is entered the "newvalue?" prompt is repeated
until an approprate response is entered.
To return from
type a single CR in response to the "element #" prompt.
This illustrates the use of
to change the members of a three element integer array with initial
values of 0, 100, and 400. The subroutine call is:
The interaction with the user might look as follows:
element # 0
= 0 newvalue?
element # 1
= 100 newvalue? a
illegal element #
element # 2
= 400 newvalue? -4
After this interaction the array values are 0, 10, and -4.
will print an error message to the standard error device and will
return -1 if it cannot write to the standard output device.