I am trying to change the value of ydot[] in func() so that I can use it in my ode() function. However, it seems like I do not have access to ydot[] anymore after I called func(). I am passing func() into ode() as a function pointer called dydt. Here are my two functions:
    void func(double t, double y[], double ydot[])
    {
        for(int i = 0; i < 18; i++){
            ydot[i] = y[i]+1;
        }
    }
    typedef void (*dydt_func)(double t, double y[ ], double ydot[ ]);
    void ode(double y0[ ], double yend[ ], int len, double t0,
             double t1, dydt_func dydt)
    {
        double ydot[len];
        dydt = &func;
        //This prints out all the value of ydot[] just fine
        for (int i = 0; i < 18; i++){
            cout << ydot[i] << ",";
        }
        dydt(t1, y0, ydot);
        //This SHOULD print all the revised value of ydot[]
        //But I get an error instead:
        //Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)
        for (int i = 0; i < 18; i++){
            cout << ydot[i] << ",";
        }
    };
I have access to ydot[] just fine before I called dydt(). Is there something wrong with the way I use function pointer? Or should I pass a pointer of ydot[] or something to func() instead? Thank you guys for helping!
 
     
    