• Source
    1. #include <stdio.h>
    2. #include <stdlib.h>
    3.  
    4.  
    5. typedef struct
    6. {
    7. int pwm;
    8. int current;
    9. } filcal_struct;
    10.  
    11. void dataFunction(filcal_struct **filcalTable, int size);
    12.  
    13.  
    14. void dataFunction(filcal_struct **filcalTable, int size)
    15. {
    16. int i;
    17.  
    18. printf("*** %s init ***\n", __FUNCTION__);
    19. for (i=0; i<size; i++)
    20. {
    21. filcalTable[i]->pwm = rand();
    22. filcalTable[i]->current = rand();
    23.  
    24. printf("point %i: pwm = %i, current = %i\n", i, filcalTable[i]->pwm, filcalTable[i]->current);
    25. }
    26. }
    27.  
    28. int main(void) {
    29.  
    30. filcal_struct *data;
    31. int i;
    32. #define TABLE_SIZE 4
    33.  
    34. // init
    35. data = malloc(TABLE_SIZE * sizeof(filcal_struct *));
    36. for (i=0; i<(int)TABLE_SIZE; i++)
    37. {
    38. data[i] = malloc(sizeof(filcal_struct));
    39. }
    40.  
    41. // go crunch the data
    42. dataFunction(&data, TABLE_SIZE);
    43. // dataFunction(&data, 3);
    44.  
    45. // report
    46. printf("*** %s usage ***\n", __FUNCTION__);
    47. for (i=0; i<(int)TABLE_SIZE; i++)
    48. {
    49. printf("point %i: pwm = %i, current = %i\n", i, data[i]->pwm, data[i]->current);
    50. }
    51.  
    52. return 0;
    53. }
    54.