Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Passing a three dimensional array

Reply
Thread Tools

Passing a three dimensional array

 
 
Nitin
Guest
Posts: n/a
 
      03-07-2006
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

 
Reply With Quote
 
 
 
 
Xavier
Guest
Posts: n/a
 
      03-07-2006
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

 
Reply With Quote
 
 
 
 
Prashant Mahajan
Guest
Posts: n/a
 
      03-08-2006

> 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.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      03-08-2006
"Prashant Mahajan" <(E-Mail Removed)> 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" <(E-Mail Removed)> 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) http://www.velocityreviews.com/forums/(E-Mail Removed) <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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To convert a one dimensional array into a two dimensional array using C amrutha0303 Software 0 08-03-2010 10:02 PM
Re: Three Mobile --> Skype on three (Non-three [Symbian - Nokia] handsets) Harry Stottle UK VOIP 0 01-05-2010 08:59 AM
How do copy Strings from a single dimensional array to double dimensional array Venkat C++ 4 12-05-2003 09:23 AM
Re: Two dimensional pointers and Two dimensional arrays John Harrison C++ 4 08-19-2003 04:00 PM
Re: Two dimensional pointers and Two dimensional arrays Alf P. Steinbach C++ 0 08-18-2003 08:25 AM



Advertisments