我有大量字符串需要存储在字符数组中,并且需要能够循环遍历所有字符串。
此外,这些字符串不会改变,所以我希望矩阵是永久的,最好存储在头文件中。
有人能指出我正确的方向吗?
我正在使用 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/