exch - interactively inspect and change values of elements in an integer array


exch (ptr, nelt)
int *ptr, nelt;


exch allows the user to inspect and change the value of any one of nelt integers in the array beginning at ptr. 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 nelt -1 followed by a CR (pressing the return 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 exch 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, exch 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 exch type a single CR in response to the "element #" prompt.


This illustrates the use of exch to change the members of a three element integer array with initial values of 0, 100, and 400. The subroutine call is: exch(array,3); The interaction with the user might look as follows:
element # 0
	= 0 newvalue? 
element # 1
	= 100 newvalue? a
	newvalue? 10
element #3
illegal element #
element # 2
	= 400 newvalue? -4
element # 
After this interaction the array values are 0, 10, and -4.




exch will print an error message to the standard error device and will return -1 if it cannot write to the standard output device.