这是我之前查询的扩展 - C 中的字符串指针数组
我在 C 中有这个工作示例代码
int main(void)
{
char *array1 = "12345";
char *array2 = "abcde";
char *array3 = "67890";
char *array4 = "fghij";
char *array_2d[4];
array_2d[0] = array1;
array_2d[1] = array2;
array_2d[2] = array3;
array_2d[3] = array4;
int i,j;
for(i = 0; i<=3 ; i++ ) {
for(j = 0; j<=4 ; j++) {
printf("%c", array_2d[i][j]);
}
printf("\n");
}
}
我想取消引用
*array1 to *array4
IE
array_2d[0] -> "12345"
....
array_2d[3] -> "fghij"
并不是
array_2d[0] -> array1 -> "12345"
....
array_2d[3] -> array4 -> "fghij"
这可能吗 ?我可能想将 array_2d 增加到 [8] 并说
array_2d[4] -> array1 -> "ABCDE"
....
array_2d[7] -> array4 -> "FGHIJ"
我希望这看起来很清楚......
编辑 -
我想我明白了。这就是我想要做的。
char *array1 = "12345";
char *array2 = "abcde";
char *array3 = "67890";
char *array4 = "fghij";
char *array_2d[8];
array_2d[0] = array1;
array_2d[1] = array2;
array_2d[2] = array3;
array_2d[3] = array4;
array1 = "AAAAA";
array2 = "BBBBB";
array3 = "CCCCC";
array4 = "DDDDD";
array_2d[4] = array1;
array_2d[5] = array2;
array_2d[6] = array3;
array_2d[7] = array4;