Returning an array

Hello,
I am trying to implement a simple function to return an array and I'm not having much luck. The program compiles but I am having trouble calling the array. Help.

Here is the function. I'm fairly new to programming and didn't even realize I needed to make this function a pointer until I found assistance on another thread. Then again it didn't work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
float *coriolus (const int xin)
        {
        const int xres=300;      //Cross Process resolution
        //const float dia=15.5;
        const float od=15.6;     //Plate OD
        const float id=10.5;     //Plate ID
        const float pathwidth=(od - id)/2;   //inches
        const int pxwidth = floor(pathwidth*xres);  //pixel width

        const int columns = floor(pxwidth/xin); 
        float *centers = new float[columns];

        for (int i=0; i < columns; i++){
            centers[i]=(xin/2)+ (i * xin);
            }
        return centers;
        }


I'm not done with this function but before continuing I'm just trying to get this part right. I would like to be able to call this function and get an array.

I have tried a few different ways of calling it including

float centers = coriolus(280);
and
float centers[] = coriolus(280);
What am I missing?
You're returning a pointer to a float, so you should catch it with a pointer to a float:

float* centers = coriolus(280);
Do mind that you have no way of knowing the size of the array once you return it.
Topic archived. No new replies allowed.