Я пытаюсь вызвать значения, хранящиеся в 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};
был его источником.
Может ли кто-нибудь дать мне несколько указателей?
'ошибку, показанную в attachment' - я не могу найти ошибку в исходном коде, ни в должности, где это? –
Вы не * вызываете * массивы. Вы определяете, объявляете, получаете доступ или изменяете их. –
И ваш код имеет неопределенное поведение, даже в стандартах, принимающих VLA-s. Вы хотите «int z = 9;» по крайней мере. –