# include # include # include "vector.h" /******************************************************************************/ void vector ( int *x_in, int *x_out ) /******************************************************************************/ /* Purpose: vector() stores, saves, and returns a vector x of 3 entries. Discussion: vector ( x_in, NULL ) copies the values in x_in into the internal vector x_default. vector ( NULL, x_out ) copies the values in x_default into the output vector x_out. vector ( x_in, x_out ) copies the values in x_in into the internal vector x_default, and returns these same value in the output vector x_out. vector ( NULL, NULL ) prints the values in x_default. Licensing: This code is distributed under the MIT license. Modified: 11 October 2025 Author: John Burkardt Input: int *X_IN: NULL or the address of X. Output: int *X_OUT: the current value of X. Local: int *X_DEFAULT: the internal value of X. */ { int i; static int x_default[3] = { 1, 2, 3 }; /* New values, if supplied on input, overwrite the current values. */ if ( x_in ) { for ( i = 0; i < 3; i++ ) { x_default[i] = x_in[i]; } } /* The current values are copied to the output. */ if ( x_out ) { for ( i = 0; i < 3; i++ ) { x_out[i] = x_default[i]; } } /* As a check, print current items. In practice, this code would do its work silently. */ if ( x_in ) { printf ( " x_in = (%d,%d,%d)\n", x_in[0], x_in[1], x_in[2] ); } else { printf ( " x_in = NULL\n" ); } if ( x_out ) { printf ( " x_out = (%d,%d,%d)\n", x_out[0], x_out[1], x_out[2] ); } else { printf ( " x_out = NULL\n" ); } printf ( " x_default = (%d,%d,%d)\n", x_default[0], x_default[1], x_default[2] ); return; }