c - 如何在 C 中将 char* 添加到 char**

标签 c arrays pointers

我在 C(不是 C++)中有一个 char 数组。类型是 char**。我知道它的长度,但元素的长度是未知的。 我还有另一个 char* 数组。 需要将此 char* 作为最后一个元素附加到我的 char**。

最佳答案

char* arr1[]; //known length with some already filled elements

上述数组的每个元素都是一个指向字符数组的指针。

char *new = "lastElem" // this is the string you have to append

假设,arr1 有 n 个元素(每个元素都是一个字符串)。然后,

arr1[++n] = new; // this should do it, provided space exists in arr1 and you already have the //character array 'new'.

关于c - 如何在 C 中将 char* 添加到 char**,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14184157/

相关文章:

arrays - swift:二维数组和字典之间的区别

c - C 中指向常量的指针

c++ - 获取指针的地址

c - 整数数组的 malloc 和 realloc 大小

c - 对char数组的更改在printf中不可见

c - Memcpy() 适用于越界内存?

c - 将数组从一个函数传递到另一个函数

python - 如何通过 SWIG 在 Python 和 C 之间编码指向 cstring 的指针

php - 如何使用 PHP 根据索引值对数组进行排序

c++ - 如何序列化共享/弱指针?