title: Initializing an array of structs in C then dereference later
body: <p>I'm trying to build a serial command interpreter, so I want to store my commands in an array. I want each command to have a name and a function pointer so that I can compare the command name to what I typed into and then call the function. I'm not that good with C, so please help! Here is what I have so far.</p>
  
  <p>The command array will be an array of structs. Each struct will have a string and a function pointer. There are errors here, but I don't know how to fix them. These are done before main.</p>
  
  <pre><code>typedef struct cmdStruct {
      char cmd[16];
      void (*cmdFuncPtr)(void);
  }CmdStruct;
  
  void (*ledFuncPtr)(void);
  void (*cmd2FuncPtr)(void);
  
  // assign pointers to functions
  ledFuncPtr = &amp;LedFunction;
  cmd2FuncPtr = &amp;Cmd2Function;
  
  //build array of structs
  CmdStruct cmdStructArray[] = cmdStructArray = { {"led",   ledFuncPtr   },
                                                  {"cmd2",  cmd2FuncPtr  },  };
  </code></pre>
  
  <p>Later on, I will go through the struct array to compare it to the received command.</p>
  
  <pre><code>// go through the struct array to do string comparison on each struct's string member
  for (int i = 0; i &lt; sizeof(cmdStructArray); i++) {
      // string comparison of received command and string of struct
      if(strcmp(cmdStructArray[i].cmd, receivedCmd)==0) {
          // dereference function pointer
          (*cmdStructArray[i].cmdFuncPtr)(void);
      }
  }
  </code></pre>
  
  <p>What parts am I doing wrong, and how do I fix them?</p>