472,955 Members | 2,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,955 software developers and data experts.

Passing a three dimensional array

Hi all

How to pass a 3-D array from the main program and access it in the
subroutine.

for example

void main()
{
.....
float a_slope_n_river_width[250][200][5];
....
/*read values from file*/
....
fn_populate_slope_file ( v_x_pixels, v_y_pixels,
a_slope_n_river_width, v_pixel_length);
...
...
}

void fn_populate_slope_file ( int v_x_pixels, int v_y_pixels, float
a_slope_n_river_width[v_y_pixels][v_x_pixels][5], float v_pixel_length
) // Generate slope array
{
/* Here I want to access the element of three dimensional array */

}

This piece of code is not working ... Please let me know the error

Thanks in advance

Regards
Nitin

Mar 7 '06 #1
3 2957
Nitin wrote:
Hi all

How to pass a 3-D array from the main program and access it in the
subroutine.

for example

void main()
{
.....
float a_slope_n_river_width[250][200][5];
....
/*read values from file*/
....
fn_populate_slope_file ( v_x_pixels, v_y_pixels,
a_slope_n_river_width, v_pixel_length); may be your v_x_pixels, v_y_pixels are not initialized with values <= dim ...
...
}

void fn_populate_slope_file ( int v_x_pixels, int v_y_pixels, float
a_slope_n_river_width[v_y_pixels][v_x_pixels][5], float v_pixel_length
) // Generate slope array
{
/* Here I want to access the element of three dimensional array */

}

This piece of code is not working ... Please let me know the error

Thanks in advance

Regards
Nitin


if your compiler accepts C99 it may be ok...

I had juste one trouble with your code : your array is too large...
(segmentation fault occurs ... and disapear With small v_x_pixels, v_y_pixels)

What is YOUR trouble?
Xavier

Mar 8 '06 #2
void fn_populate_slope_file ( int v_x_pixels, int v_y_pixels, float
a_slope_n_river_width[v_y_pixels][v_x_pixels][5], float v_pixel_length


I am not sure if the compiler you are using implements C99 or not but
you can try

void n_populate_slope_file (int v_x_pixels, int v_y_pixels, float***
a_slope_n_river_width, float v_pixel_length )

and use the values v_x_pixels, v_y_pixels and v_pixel_length to access
the 3D Array
using pointer.

Mar 8 '06 #3
"Prashant Mahajan" <th****************@gmail.com> writes:
void fn_populate_slope_file ( int v_x_pixels, int v_y_pixels, float
a_slope_n_river_width[v_y_pixels][v_x_pixels][5], float v_pixel_length


I am not sure if the compiler you are using implements C99 or not but
you can try

void n_populate_slope_file (int v_x_pixels, int v_y_pixels, float***
a_slope_n_river_width, float v_pixel_length )

and use the values v_x_pixels, v_y_pixels and v_pixel_length to access
the 3D Array
using pointer.


Please don't snip attribution lines (the lines that say
"So-and-so" <fo*@bar.com> writes:).

There's nothing C99-specific in your declaration of n_populate_slope_file.
C99 does add some features in the area of array-like parameters,
but you don't use any of them.

And keep carefully in mind that a pointer-to-pointer-to-pointer is not
a way to access the elements of a true 3-dimensional array (i.e., an
array of arrays of arrays). See section 6 of the comp.lang.c FAQ.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sam | last post by:
Hello all I have a two dimensional array (the dimensions are not known) that needs to be passed to fortran from c++, allocate the dimensions of the array in fortran code, do some filling up of...
2
by: NM | last post by:
Hello all, I am supposed to do some mixed programming with c++ and fortran. I was succeeful in exchanging the 2D arrays from fortran to c++ and the other way, but was unable to that same with...
10
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
3
by: Alex Munk | last post by:
I would like to be able to pass a 2-dimensional array to a function as a string parameter. In the called function I would like to be able to convert the string back into a 2-dimensional array....
3
by: SQLScott | last post by:
I have looked all over and I cannot find an example or information on passing a multi-dimensional array. Well, that is not true. I found a close example in C++ but it didn't work when I...
4
by: entitledX | last post by:
Hi, I'm trying to use the HDF library to read a few HDF files that I need to process. The data in each file varies in rows, but the columns remain constant. Because of that, I had dynamically...
2
by: nleahcim | last post by:
Hi - I am working on writing a number of matrix manipulation functions. The most basic one was a printing algorithm - and it shows the problem I'm having. I'm passing it a pointer a mutidimensional...
5
by: CapCity | last post by:
I'm sure I'm missing something simple - I do not code in C regularly, and the breaks are long enough for me to forget. The situation I have is I need to create an array but I do not know the...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.