C中的字符串数组() [英] String array() in C
问题描述
嘿,
我需要一个结构来存储c中的字符串数组,例如
索引内容
-------- -----------
0 word1
1 word2
2
3
4
5
这是强制性消息
我需要一个结构来存储c中的字符串数组,例如
索引内容
-------- -----------
0 word1
1字2
2字3
3字4
4字5
5字6 br $>
--------------------
我当时想用char **,但是我不想使用双指针,
如果有一个简单的方法来解决这个问题吗?
谢谢。
< Ja ******** @ gmail.comwrote in message
news:11 *** ***************** *@h2g2000hsg.googlegrou ps.com ...
这是强制性消息
我需要一个结构来存储c中的字符串数组,例如
索引内容
------ - -----------
0 word1
1 word2
2 word3
3字4
4字5
5字6
------------------- -
我想用char **,但我不想用双指针,
如果有一个简单的方法可以绕过这个?
编号你可以声明一个指针数组,但实际上这个数组只是一个
char **语法。
如果你不知道你在运行时需要多少字符串
char ** list;
int N;
和malloc()是要走的路。
如果你这样做
char * list [N];
是O. K.
但是你很少需要原始的字符串表。通常字符串是
绑定的东西。所以
struct mydata
{
char * word;
int value;
double value2;
};
其中value和value2是任意的东西,例如计数,与每个相关联的
"单词,更常见。
-
免费游戏和编程好东西。
http://www.personal.leeds.ac.uk/~bgy1mm
Ja********@gmail.com 写道:
这是强制性消息
我需要一个结构来在c中存储一个字符串数组,例如
索引内容
-------- -----------
0字1
1字2
2字3
3字4
4字5
5 word6
--------------------
我在考虑使用char **,但我不想使用双指针,
如果有一个简单的方法来解决这个问题?
您的字符串数量是固定的还是可变的?
>
Hey,
I need a structure to store a string array in c, for example
Index Content
-------- -----------
0 word1
1 word2
2
3
4
5
Here is the compelte message
Hi,
I need a structure to store a string array in c, for example
Index Content
-------- -----------
0 word1
1 word2
2 word3
3 word4
4 word5
5 word6
--------------------
I was thinking to use char**, but I don''t want to use double pointer,
if there an easy way to get around this?
Thanks.
<Ja********@gmail.comwrote in message
news:11*********************@h2g2000hsg.googlegrou ps.com...Here is the compelte message
Hi,
I need a structure to store a string array in c, for example
Index Content
-------- -----------
0 word1
1 word2
2 word3
3 word4
4 word5
5 word6
--------------------
I was thinking to use char**, but I don''t want to use double pointer,
if there an easy way to get around this?
No. You can declare an array of pointers, but really the array is just a
char ** dressed up with different syntax.
If don''t know how many string you need at run time
char **list;
int N;
and malloc() is the way to go.
If you do
char *list[N];
is OK.
However you very rarely need raw tables of strings. Usually the string is
tied to something. So
struct mydata
{
char *word;
int value;
double value2;
};
where value and value2 are arbitrary things, eg counts, associated with each
"word", is more common.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
Ja********@gmail.com wrote:
Here is the compelte message
Hi,
I need a structure to store a string array in c, for example
Index Content
-------- -----------
0 word1
1 word2
2 word3
3 word4
4 word5
5 word6
--------------------
I was thinking to use char**, but I don''t want to use double pointer,
if there an easy way to get around this?Is your number of strings fixed, or variable?
Brian
这篇关于C中的字符串数组()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!