我正在尝试调用存储的值temp[z]
,然后使用函数显示它。这是代码:
/* File: StudentID_Surname.c - e.g. 1234567_Wilson.c
* This program finds the range between highest and lowest value of a 2-D array */
#include <stdio.h>
#define NROW 3
#define NCOL 3
/* Write a function
void disp_arr(int a[NROW][NCOL]) { ... }
where a[][] is the 2-D array
Print the entire array to the screen. */
disp_arr( int temp );
int main(void)
{
/* declare needed variables or constants, e.g. */
int ar[NROW][NCOL];
int rows, cols;
int z = 0;
int temp[z] = {1,2,3,4,5,6,7,8,9}; /* Storing 9 numbers */
/* prompt for the user to enter nine positive integers to be stored into the array */
for ( rows = 0 ; rows < 3 ; rows++ )
{
for ( cols = 0 ; cols < 3 ; cols++ )
{
printf( "Please enter 9 positive integers : " );
scanf( "%d", &ar[rows][cols] );
/* Store values in the temp[z] = {1 2 3 4 5 6 7 8 9}*/
temp[z] = ar[rows][cols];
z += 1; /* Increase the array in temp[z] */
}
printf("\n");
}
/* Call disp_arr to display the 3 x 3 board */
disp_arr( temp[z] );
}/* end main */
disp_arr( int storedValue )
{
int x,y;
for ( x = 0 ; x < 3 ; x++ )
{
for ( y = 0 ; y < 3 ; y++ )
{
printf( "%d\t", storedValue );
}
printf("\n%d");
}
return storedValue;
}
当我尝试执行代码时,我的编译器给了我附件中显示的错误。我猜代码int temp[z] = {1,2,3,4,5,6,7,8,9};
是它的来源。
谁能给我一些指示?