/* * ===================================================================== * Demonstrate Passing of Multi-dimensional Arrays to Functions * * Copyright (C) 1994-96 by Mark Austin and David Mazzoni. * * This software is provided "as is" without express or implied warranty. * Permission is granted to use this software on any computer system, * and to redistribute it freely, subject to the following restrictions: * * 1. The authors are not responsible for the consequences of use of * this software, even if they arise from defects in the software. * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * 4. This notice is to remain intact. * ===================================================================== */ #include enum { NoRows = 3, NoCols = 2 }; /* sizes/limits */ /* * ================================== * Print message and details of array * ================================== */ void printArrayDetails( char *cpMessage, const float faaVals[ NoRows ][ NoCols ] ) { int ii, ij; printf("\n"); for( ii = 0; ii < NoRows; ii = ii + 1 ) { printf("*** %s \t:", cpMessage ); for( ij = 0; ij < NoCols; ij = ij + 1 ) { printf(" faaVals[%2d][%2d] = %5.1f ", ii, ij, faaVals[ii][ij]); } printf("\n"); } } /* * =============================== * Print array and update contents * =============================== */ void testFunction( float faaVals[ NoRows ][ NoCols ] ) { printArrayDetails("In testFunction()", faaVals ); faaVals[2][0] = 100; faaVals[2][1] = 200; } /* * ===================================================== * Test passing of multi-dimensional arrays to functions * ===================================================== */ int main( void ) { static float faaVals[ NoRows][ NoCols ] = { { 1.0, 2.0 }, /* two dim. array */ { 3.0, 4.0 }, { 5.0, 6.0 } }; /* [a] : Print array faaVals before calling TestFunction() */ printArrayDetails("In main()", faaVals ); /* [b] : Call TestFunction, and change contents of faaVals */ testFunction( faaVals ); /* [c] : Print array faaVals after returning from TestFunction() */ printArrayDetails("Back in main()", faaVals ); }