我目前正在为微处理器编写 C 代码,我遇到了一些我无法解释的事情。我已经使用函数指针实现了命令行界面。为此,我创建了一个结构体,其中包含命令的名称、指向要运行的函数的指针以及帮助说明。
typedef void(*command)(char *);
typedef struct commandStruct {
char const *name;
command execute;
char const *help;
} commandStruct;
const commandStruct commands[] =
{
{"led", CmdLed, "Turns on or off the LED1"},
{"AT+START_SIM", start_simulation, "Starts the simulation"},
{"AT+STOP_SIM", stop_simulation, "Stops the simulation"},
{"",0,""} //End of table indicator.
};
void exec_command(char *buffer)
{
uint16 i = 0;
char *cmd = buffer;
char *args;
while (buffer[i])
{
if(buffer[i] == '=')
{
buffer[i] = 0;
args = buffer + i + 1; …Run Code Online (Sandbox Code Playgroud)