vendredi 22 juillet 2016

2D array print error

This is my code snippet:

float *fittedLine[NO_OF_INTERVALS];
int i;
for(k=0;k<NO_OF_INTERVALS;k++){
    fittedLine[k] = plotLines(tStart, tEnd, yStart, yEnd);
    for(i=0;i<14;i++)
        printf("%fn", fittedLine[k][i]);
}

My problem: The print statement is not giving proper outputs; Garbage values are printed.

I tried debugging by putting a breakpoint in line 5 and tried printing fittedLine[0][0], fittedLine[0][1] and so on. That gives proper output. But when coming to the print statement, things start to fall apart. What is happening here? plotLines returns a 1D array.

plotLines function:

float * plotLines(float t0, float tf, float y0, float yf){
    float m = (yf - y0)/(tf - t0);
    float t = t0;
    int i = 0;
    float y[200];
    while(t<tf){
        y[i] = m*t + yf - m*tf; ///y - y1 = m(x - x1)
        i++;
        t = t+SAMPLINGTIME;
    }
    return y;

}

Aucun commentaire:

Enregistrer un commentaire