sách gpt4 ai đã đi

C: Tạo, truyền và truy cập các mảng con trỏ hằng số tới các chuỗi hằng số

In lại 作者:行者123 更新时间:2023-12-04 12:31:55 28 4
mua khóa gpt4 Nike

出于某种原因,这不起作用:

const char * str_reset_command = "\r\nReset";
const char * str_config_command = "\r\nConfig";

const char *commands[2] = {
&str_reset_command,
&str_config_command
};

这是正确的吗? (一定是其他地方的代码导致了问题吗?)

(我在基准 8 位微 Controller 上运行它并且调试能力非常有限)

澄清:

这是我想要实现的:

const char * str_reset_command = "\r\nReset";
const char * str_config_command = "\r\nConfig";
const char * str_start_command = "\r\nStart";
const char * str_end_command = "\r\nEnd";

const char * const group0[1] = {
str_reset_command
}
const char * const group1[2] = {
str_reset_command,
str_start_command
}
const char * const group2[3] = {
str_reset_command,
str_start_command,
str_end_command
}
void doStuffToCharacter(unsigned char the_char){
// ....
}
void doStuffToGroup(char ** group, unsigned char num_strings){
for (unsigned char s=0; s < num_strings; s++){
unsigned char idx = 0;
while (group[s][idx]){
doStuffToCharacter(group[s][idx]);
}
}
}
void main (void){
doStuff(group0, 1);
doStuff(group1, 2);
doStuff(group2, 3);
}

除了更正之外,我们欢迎任何关于执行上述操作的更简洁的建议。

命令字符串的各种组合需要发送到函数进行处理。所有字符串都在 ROM 中,指向它们的指针组也是如此。

1 Câu trả lời

您创建了一个指针数组,但您传递的是指针的地址(即指向指针的指针)。你应该做的是这个-

    const char* commands[2]= {str_reset_command, str_config_command};

关于C: 创建、传递和访问指向常量字符串的常量指针数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21429773/

28 4 0
Bài viết được đề xuất: r - R 中使用 rggobi 的交互式图形
Bài viết được đề xuất: php - 在 Wordpress 多站点中单点登录
Bài viết được đề xuất: r - 包含 NA 的数据的聚集标准错误
Bài viết được đề xuất: azure - Windows Azure 上的 Jenkins 从属连接问题
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com