'Read the value of pointer to pointer array of struct passed to a function

Context: Recently I've started programming in a more professional way and currently I'm working on a C driver library that should look decent in code both functionally and esthetically so I've just started to use the consept of pointers more intensely and not very experienced with it in relation to how it works on code.

Problem: Basically I'm trying to read a values inside each of the struct with a for loop inside initFunt() My solution to that was to create a struct pointer group for all the created btn_params_t instants and pass that pointer group to initFunc() and from init access each struct member with something like "Btn Pin in the first struct is: %d", BtnPointer[0]->BtnPin

Here's basically the code to explain it:

    #include <stdio.h>
#include <stdlib.h>
#include <stdint.h>


typedef struct btn_params_t
{

    uint8_t BtnPin;
    uint8_t BtnActiveState;
    uint8_t BtnPinPullUp;
    uint8_t BtnPinPullDown;
    void (*PressedISR)();
    void (*ReleasedISR)();


} btn_params_t;

void initFunc(btn_params_t **BtnPointer){


  printf("Btn Pin in the first struct is: %d", BtnPointer[0]->BtnPin);
}

int main(int argc, char *argv[]) {

  btn_params_t Btn0Params = {
                .BtnPin = 4,
                .BtnActiveState = 0,
                .BtnPinPullUp =  1,
                .BtnPinPullDown = 0
                
  };
  
  btn_params_t Btn1Params = {.BtnPin = 32};


  btn_params_t** BtnGroup = {&Btn0Params, &Btn1Params};

  initFunc(BtnGroup);

}

How'd you do such a thing?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source