c语言的库函数strncmp()有比较字符的功能,两个字符串相同会返回0,不相同返回-10。
#include "stm32f10x.h"
#include "string.h"
void str_once_function(char *str)
{
if(!strncmp(str,"功能1",3))
{
//fun1....
}
if(!strncmp(str,"功能2",3))
{
//fun2....
}
if(!strncmp(str,"功能2",3))
{
//fun3....
}
}
int main()
{
str_once_function("功能1");
retutn;
}
一些重复的代码这样写function("fun1")有一种输入命令的感觉