2

我有以下内容;

const CHAR string_1[] PROGMEM = "String 1";
const CHAR string_2[] PROGMEM = "String 2";
const CHAR string_3[] PROGMEM = "String 3";
const CHAR string_4[] PROGMEM = "String 4";
const CHAR string_5[] PROGMEM = "String 5";

const CHAR *string_table[] PROGMEM  = 
{
    string_1,
    string_2,
    string_3,
    string_4,
    string_5
};

我将如何保存 string_table 的这个地址,以便我可以在函数中调用它;

CHAR acBuffer[20];
UCHAR ucSelectedString = 2; // get string number 3
//
    pcStringTable = string_table ...?? What is the proper line here??
//
strcpy_P(acBuffer, (char*)pgm_read_byte(&(pcStringTable[ucSelectedString])))

根据下面的评论,我也改变了结构;

typedef struct
{
...
CHAR **pasOptions;

然后我尝试分配string_table给它;

stMenuBar.pasOptions = string_table;

编译器抛出这个警告;

warning: assignment from incompatible pointer type

还有什么想法吗?

4

1 回答 1

3

string_table是一个指向字符串的指针数组。数组可以衰减为(一维,因为那是唯一的一种)指针就好了。

因此,字符串数组的数组可以表示为指向(字符的指针 [认为:字符串])的指针 [认为:数组]。

const char **pcStringTable = string_table;

然后您可以将其作为任何其他一维数组访问:

printf("%s", pcStringTable[2]);
于 2012-05-04T06:08:51.743 回答