void displayString(int i, int isDraw, float val, char** stringArray, int x, int y) { (isDraw ? LCD_DisString_Not(x, y, (char *)stringArray[(int)val]) : LCD_DisString(x, y, (char *)stringArray[(int)val])); }这个函数里stringArray要接收const char gcszOnOff[][48] = {// 投入退出 { "退出" }, { "投入" } }; const char gcszLcdSynctmMode[][32] = {//LCD对时方式 {"主站"}, {"北斗GPS"} };,该怎么修改
时间: 2024-03-02 08:47:49 浏览: 22
你可以将函数修改为这样:
```c++
void displayString(int i, int isDraw, float val, const char* stringArray[], int x, int y) {
if(i == 0){
if(isDraw){
LCD_DisString_Not(x, y, (char *)stringArray[(int)val]);
}else{
LCD_DisString(x, y, (char *)stringArray[(int)val]);
}
}else if(i == 1){
if(isDraw){
LCD_DisString_Not(x, y, (char *)stringArray[(int)val]);
}else{
LCD_DisString(x, y, (char *)stringArray[(int)val]);
}
}else{
// 处理未知情况
}
}
```
然后在调用该函数时,你可以将`const char gcszOnOff[][48]`和`const char gcszLcdSynctmMode[][32]`分别传递给`stringArray`参数,例如:
```c++
const char* gcszOnOff[] = {"退出", "投入"};
const char* gcszLcdSynctmMode[] = {"主站", "北斗GPS"};
displayString(0, isDraw, val, gcszOnOff, x, y);
displayString(1, isDraw, val, gcszLcdSynctmMode, x, y);
```
注意,`stringArray`参数的类型是`const char*`指针的指针,因此你需要将`const char gcszOnOff[][48]`和`const char gcszLcdSynctmMode[][32]`转换为指向指针的指针。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)