我有 2 个二维数组。在某些时候,我需要选择两者之一并对其进行循环。我需要什么样的指针来指向二维数组才能对其进行循环?
const char *a[] = {
"example1",
"example2",
NULL
};
const char *b[] = {
"example1",
"example2",
"example3",
"example4",
"example5",
NULL
};
const char *pointer = a;
int count = 0;
while(pointer != NULL)
{
puts(pointer[count]);
count++;
}
最佳答案
你只需要一个*
:
const char **pointer = a;
你的循环条件也是错误的 - 我想你想要:
while (pointer[count] != NULL)
关于c - 如何遍历二维字符数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14656041/