c - 从函数内部进行矩阵访问

标签 c arrays string character header-files

我有大量字符串需要存储在字符数组中,并且需要能够循环遍历所有字符串。

此外,这些字符串不会改变,所以我希望矩阵是永久的,最好存储在头文件中。

有人能指出我正确的方向吗?

我正在使用 C 语言工作,不知道解决这个问题的最佳方法。

谢谢!

最佳答案

header 中的变量定义可能不是一个好主意,请考虑替代方案:

// source.c contains
const char *const strings[] = {
    "string1", "string2", NULL 
};

// source.h contains
extern const char *const strings[];

// include source.h anywhere and loop through the strings like this:
for (const char *const *str = strings; *str != NULL; ++str)
    // use *str

关于c - 从函数内部进行矩阵访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11996519/

相关文章:

c - 如何确定 pthread 使用的内存

c - 警告 : format '%c' expects argument of type 'char *' , 但参数 3 的类型为 'int'

arrays - Ruby 最长回文子串函数中的奇怪输出

c - 局部数组和数组索引变量如何存在于内存中?

python - Tensorflow:无法从 tfrecord 中提取文件名

javascript - Node.js 同步读取文件作为字符串(不是缓冲区)

c++ - wchar_t* 到字符串的转换

c - 为什么 pthread_cond_wait 有虚假唤醒?

c - GNU 如何跟踪文件更改?

javascript - 根据另一个数组中的值删除嵌套对象数组中的值