C中的2D字符数组初始化 [英] 2D character array initialization in C
本文介绍了C中的2D字符数组初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试构建需要传递给期望char **
I am trying to build a list of strings that I need to pass to a function expecting char **
如何构建此数组?我想传递两个选项,每个选项的字符数少于100个.
How do I build this array? I want to pass in two options, each with less than 100 characters.
char **options[2][100];
options[0][0] = 'test1';
options[1][0] = 'test2';
这不能编译.我到底在做什么错?如何在C中创建2D字符数组?
This does not compile. What am I doing wrong exactly? How do I create a 2D character array in C?
推荐答案
C字符串用双引号引起来:
C strings are enclosed in double quotes:
const char *options[2][100];
options[0][0] = "test1";
options[1][0] = "test2";
重新阅读您的问题和评论,尽管我猜您真的 想要做的是这样的事情:
Re-reading your question and comments though I'm guessing that what you really want to do is this:
const char *options[2] = { "test1", "test2" };
这篇关于C中的2D字符数组初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文