I'm just making a mess out of this. I have a function that is supposed to take a one-dimensional array, do some calculations with its values, and then return a similar array with the results of the calculation. I don't necessarily care whether it returns the same array (with new values) or if it creates a new array at a different memory location and returns that. Here is what I've got at the moment. There are errors all over this, but I don't know what I am doing wrong. Can anyone help?
double s = 10;
double b = 2.6666;
double r = 28;
double (*newVertex(double vtx[3] )) [] {
static double newVtx[3];
/* Coordinates */
double x = vtx[0];
double y = vtx[1];
double z = vtx[2];
double dt = 0.001;
double dx = s*(y-x);
double dy = x*(r-z)-y;
double dz = x*y - b*z;
newVtx[0] = x + dt*dx;
newVtx[1] = y + dt*dy;
newVtx[2] = z + dt*dz;
return &newVtx;
}
int main(int argc, char *argv[]) {
int i;
/* Arrays to hold the coordinates */
double thisPt[3] = {1, 1, 1};
double nextPt[3];
for (i=0;i<1000;i++) {
printf("%5d %8.3f %8.3f %8.3f\n", i, thisPt[0], thisPt[1], thisPt[2]);
nextPt = newVertex(&thisPt);
thisPt = nextPt;
}
return 0;
}