2
期望的行爲如何使用嵌套數組作爲函數中的值?
我想定義數組的數組,並訪問在函數頂層數組的值。
我已經試過
例如:
// the array
char* myRGBColorArray[5][3] = {
{"0x00,","0x01,","0x02,"}, // i want to use this in a function
{"0x03,","0x04,","0x05,"},
{"0x06,","0x07,","0x08,"},
{"0x09,","0x10,","0x11,"},
{"0x12,","0x13,","0x14,"}
};
// the function's format
// cursor_set_color_rgb(0xff, 0xff, 0xff);
// ideally i would like to use the indexed values, like this:
cursor_set_color_rgb(myRGBColorArray[0]);
cursor_set_color_rgb(myRGBColorArray[1]); // etc
很新的C,因此仍然試圖讓我的周圍嵌套的數組頭,訪問索引值,並定義類型。
問題/ s的
- 高於正確定義的
myRGBColorArray
的type
? - 如何正確訪問數組的索引值?
僅供參考,我在玩與周圍的功能是從第二個例子在這裏 - 它改變了光標的顏色:
https://stackoverflow.com/a/18434383
#include <stdio.h>
#include <unistd.h>
void cursor_set_color_rgb(unsigned char red,
unsigned char green,
unsigned char blue) {
printf("\e]12;#%.2x%.2x%.2x\a", red, green, blue);
fflush(stdout);
}
int main(int argc, char **argv) {
cursor_set_color_rgb(0xff, 0xff, 0xff); sleep(1);
cursor_set_color_rgb(0xff, 0xff, 0x00); sleep(1);
cursor_set_color_rgb(0xff, 0x00, 0xff); sleep(1);
cursor_set_color_rgb(0x00, 0xff, 0xff); sleep(1);
return 0;
}