470,874 Members | 1,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

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 2849
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by SQLScott | last post: by
5 posts views Thread by CapCity | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.