Home > database >  Pointer Issue in C programming
Pointer Issue in C programming

Time:01-20

I'm getting an error but I don't quite understand why please share any ideas I think error about the pointer Calibrated *cal;but i don't know how to solve. I don't have any idea plese share any idea about this problem



#include <stdio.h>
#include "stdint.h"
#include"string.h"
typedef struct{

 int16_t Calibration_matrice[3][3];
 int16_t average_axis[3];
 int16_t bias[3];
 int16_t total_average;
 float   scales[3];

}Calibrated;


void get_CalibratingValues(Calibrated *cal , int16_t x_max , int16_t x_min , int16_t y_max , int16_t y_min , int16_t z_max , int16_t z_min)
{


     cal->Calibration_matrice[0][0] = x_min;
     cal->Calibration_matrice[0][1] = x_max;
     cal->Calibration_matrice[1][0] = y_min;
     cal->Calibration_matrice[1][1] = y_max;
     cal->Calibration_matrice[2][0] = z_min;
     cal->Calibration_matrice[2][1] = z_max;

     cal->bias[0] = (cal->Calibration_matrice[0][0]   cal->Calibration_matrice[0][1])/2;
     cal->bias[1] = (cal->Calibration_matrice[1][0]   cal->Calibration_matrice[1][1])/2;
     cal->bias[2] = (cal->Calibration_matrice[2][0]   cal->Calibration_matrice[2][1])/2;


     cal->average_axis[0] = (cal->Calibration_matrice[0][1] - cal->Calibration_matrice[0][0])/2;
     cal->average_axis[1] = (cal->Calibration_matrice[1][1] - cal->Calibration_matrice[1][0])/2;
     cal->average_axis[2] = (cal->Calibration_matrice[2][1] - cal->Calibration_matrice[2][0])/2;

     cal->total_average =((cal->average_axis[0]   cal->average_axis[1]   cal->average_axis[2]) / 3);

     cal->scales[0] = (float)(cal->total_average / cal->average_axis[0]);
     cal->scales[1] = (float)(cal->total_average / cal->average_axis[1]);
     cal->scales[2] = (float)(cal->total_average / cal->average_axis[2]);

}

int main()
{     Calibrated *cal;
      
      get_CalibratingValues(cal,4070,-6610,6440,-4410,4197,-5865);

       printf("%d\n",cal->Calibration_matrice[0][0]); // it is not take a value
     
    
    return 0;
}

CodePudding user response:

Your variable cal is uninitialized. Try:

  Calibrated* cal = (Calibrated *) malloc(sizeof(Calibrated));

Don't forget to dispose of it at the end:

  free(cal);

Once I do that, I get an output value of -6610.

  • Related