我如何才能使用此功能,這是一個 3D 陣列,我想從用戶那里掃描行、列、單元格的數量,然后發送 3D 陣列
#include <stdio.h>
void School (int(*ptr)[int col][int cell] );//this is a user function
void main (void){
int row ;//number of row
int col ;//number of colum
int cell ;//number of cell
printf("Enter Number OF School Layers \n");
scanf("%d",&row);
printf("Enter Number OF Classes in each Layer \n");
scanf("%d",&col);
printf("Enter Number OF Students in each Class \n");
scanf("%d",&cell);
int arr [row][col][cell];
School(arr,row,col,cell);//calling of function
}
void School (int(*ptr)[int col][int cell] ){//i want what write here
}
在這段代碼中我有問題
uj5u.com熱心網友回復:
void School (size_t layers, size_t col, size_t cell, int (*ptr)[col][cell])
{
}
uj5u.com熱心網友回復:
首先,您需要更新函式原型以在陣列引數(實際上是指向陣列的指標)之前接受維度。
void School (int rows, int cols, int cells, int arr[rows][cols][cells]);
然后呼叫它:
School(row, col, cell, arr);
實際的掃描代碼將是:
void School (int rows, int cols, int cells, int arr[rows][cols][cells]) {
for (int row = 0; row < rows; row)
for (int col = 0; col < cols; col)
for (int cell = 0; cell < cells; cell)
scanf("%d", &arr[row][col][cell]);
}
GCC 具有允許在傳遞引數之前宣告引數的擴展。
void School (int rows, cols, cells; int arr[rows][cols][cells], int rows, int cols, int cells);
這將讓您呼叫該函式:
School(arr, row, col, cell);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/315017.html
上一篇:更改陣列會復制資料嗎?
下一篇:陣列和結構指標
