Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing multidimensional arrays...

Status
Not open for further replies.

sunaj

Technical User
Feb 13, 2001
1,474
DK
Hi,

I've got this function (I didn't write it):
void polyinterp2(float x1a[], float x2a[], float **ya, int m, int n, float x1,
float x2, float *y, float *dy)

and I know that I'm supposed to supply a [1..n][1..m] array to the variable ya.
How do I do that? I don't know what ** means...
If you can, please give an example where I can see the declarations and the function call. I'll be greatfull and you'll get a star if it works :)
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Hi again,

Now I got this far:
--------------------------------------------------
//Declaring and initializing other variables
float** y;
y=new float*[n+1];
for(int i=1;i<n+2;i++)
y=new float[n+1];

//here I want to insert values into the 2D array, how?

polyinterp2(x1,x1,y,5,5,1.5,1.5,&ny,&ndy)
---------------------------------------------------

Anyone....?? Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Why is it that the simplest things sometimes can cause a lot of grey hair? [bomb]
It works like a charm now.. Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Here is a little program that i have wrote for helping:

#include <iostream.h>
#include <stdlib.h>
typedef int Array[100];
void main()
{
Array *y; // create the array (25 by 100)
y = new Array[25]; // allocating memory to it
if( y == NULL ) // test if memory have been allocated
exit(1);

for( int i = 0; i < 25; i++ ) // input the array
{
for( int j = 0; j < 100; j++ )
y[j] = 8;
}

for( i = 0; i < 25; i++ ) // output the array
{
for( int k = 0; k < 100; k++ )
cout<<&quot;[&quot;<<i<<&quot;]&quot;<<&quot;[&quot;<<k<<&quot;] = &quot;<<y[k]<<endl;
}
delete [] y; // freeing the memory that has been allocated to the array
}
 
Now for returning a 2D array,you can use this:

#include <iostream.h>
#include <stdlib.h>
typedef float Array[100];
Array *Function( int size )
{
Array *y; // create the array
y = new Array[size];// allocating memory to it ('size' by 100)

if( y == NULL ) // test if memory have been allocated
exit(1);

for( int i = 0; i < 25; i++ ) // input the array
{
for( int j = 0; j < 100; j++ )
y[j] = 1.568f;
}
return y;
}

void main()
{
Array *values;
values = Function(25);

for( int m = 0; m < 25; m++ ) // output the array
{
for( int k = 0; k < 100; k++ )
cout<<&quot;[&quot;<<m<<&quot;]&quot;<<&quot;[&quot;<<k<<&quot;] = &quot;<<values[m][k]<<endl;
}
delete [] values; // freeing the memory that has been allocated to the array
}
 
By the way the &quot;**&quot; in &quot;**ya&quot; means that the variable &quot;ya&quot; is a pointer of pointer ( a pointer that holds the address of another one ).
In this example &quot;ya&quot; will hold the address of the pointer &quot;*ya&quot; i think.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top