char **问题...... [英] char** question...

查看:89
本文介绍了char **问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C ++在掌上环境中编程并且卡住了。我
创建了一个char数组:


const char MyArray [300] [50] =

{

{" string1"},

{" string2"},

....

{" string50" ;}

}


我需要构建一个函数,它将以

char **的形式返回MyArray br />

由于内存问题,我需要这样做。


如果需要完成任何循环,我需要用代码完成那个

正在调用这个函数。


任何帮助都将不胜感激。


谢谢,

RABMissouri

I am programming in the palm environment using C++ and am stuck. I
have created an char array:

const char MyArray [300][50] =
{
{"string1"},
{"string2"},
....
{"string50"}
}

I need to build a function that will return MyArray in the form of a
char**

I need to do it this way because of memory issues.

If any looping needs to be done I would need it done with the code that
is calling the function.

Any help would be appreciated.

Thanks,
RABMissouri

推荐答案

* RAB:
* RAB:

I我正在使用C ++在掌上环境中编程并且卡住了。我
创建了一个char数组:


const char MyArray [300] [50] =

{

{" string1"},

{" string2"},

....

{" string50" ;}

}
I am programming in the palm environment using C++ and am stuck. I
have created an char array:

const char MyArray [300][50] =
{
{"string1"},
{"string2"},
....
{"string50"}
}



缺少分号。另外,你在这里有三百串

最大长度49,而不是五十串最大长度299.我从不记得

订单,因为它不是通常会使用的东西,但是给定一个带有2D数组的代码片段,很容易使用编译器进行检查。

Missing semicolon. Also, what you have here is three hundred strings of
max length 49, not fifty strings of max length 299. I never recall the
order because it''s not something one would ordinarily use, but given a
piece of code with 2D array it''s easy to check using a compiler.


我需要构建一个函数,它将以

char **的形式返回MyArray **
I need to build a function that will return MyArray in the form of a
char**



你有两个-dimensional数组,这与

指针的数组不同。


三个要求之一必须产生:


*将MyArray的声明更改为指针数组。


*更改函数声明以返回''char const

(*)[300]''(或50,无论意图如何)。


*放弃功能结果应为MyArray的要求

直接。


Assumin g,你没有太多的记忆可以使用

看来上面的第一点是最好的行动方案,即


static char const * const myArray [] =

{

" string1",

...

};

static size_t const myArray_length = sizeof(myArray)/ sizeof(* myArray);

You have a two-dimensional array, that''s not the same as an array of
pointers.

One of the three requirements has to yield:

* Change the declaration of MyArray to an array of pointers.

* Change the declaration of the function to return a ''char const
(*)[300]'' (or fifty, whatever was the intention).

* Discard the requirement that the function result should be MyArray
directly.

Assuming that you don''t have an awful lot of memory to play around with
it seems the first point above is the best course of action, i.e.

static char const* const myArray[] =
{
"string1",
...
};
static size_t const myArray_length = sizeof(myArray)/sizeof(*myArray);


我需要这样做因为记忆问题。
I need to do it this way because of memory issues.



哦,是的。 :-)

Oh, yes. :-)


如果需要进行任何循环,我需要使用

调用的代码来完成功能。
If any looping needs to be done I would need it done with the code that
is calling the function.



-

答:因为它弄乱了人们通常阅读文字的顺序。

Q :为什么这么糟糕?

A:热门帖子。

问:usenet和电子邮件中最烦人的是什么?


--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Alf,


如果我冒犯了你,很抱歉。这不是我的意图。我只是想看一下

的解决方案。


你有没有在掌上环境中编程?如果你没有一个

有64k的ram就是这样。如果想要存储数据字符串超过64k,则必须以我之前指示的形式存储。

const char MyArray [300] [50] =

{

{" string1"},

{" string2"},

....

{" string300"}

};


棘手的部分是我需要将MyArray转换为char **所以我可以将

放在列表框中。


所以问题仍然存在,如何将MyArray转换为char **?


谢谢,

RABMissouri

Alf,

Sorry if I offended you. It was not my intention. I am just looking
for a solution.

Have you ever programmed in the palm environment? If you havent one
has 64k of ram and that is it. If one wants to store strings of data
beyond 64k one has to store exactly in the form I previously indicated.
const char MyArray [300][50] =
{
{"string1"},
{"string2"},
....
{"string300"}
};

The tricky part is I need to convert MyArray to a char** so I can put
it in a listbox.

So the question still remains, how do I convert MyArray to a char**?

Thanks,
RABMissouri


* RAB:
* RAB:

Alf,


对不起,如果我冒犯了你。这不是我的意图。我正在寻找一个解决方案来获得

Alf,

Sorry if I offended you. It was not my intention. I am just looking
for a solution.



嗯?

Huh?


你有没有在掌上环境中编程?
Have you ever programmed in the palm environment?



Nope。

Nope.


如果你没有一个

拥有64k的ram就是这样。如果想要存储超过64k的数据字符串,则必须以我之前指示的形式存储。
If you havent one
has 64k of ram and that is it. If one wants to store strings of data
beyond 64k one has to store exactly in the form I previously indicated.



我发现这两个声明都不容易相信......好吧,64k可能是可信的,在一些80年代早期的早期90'的掌上电脑。但第二个

语句与此相矛盾,并且我没有听说过任何计算机或操作系统

对C或C ++数据布局提出要求以便能够

使用内存 - 我很确定你误解了一些东西。

I find neither statement easy to believe... OK, 64k might be
believable, on some old late 80''s early 90''s palmtop. But the second
statement contradicts that, and no computer or OS I have ever heard of
places requirements on the C or C++ data layout in order to be able to
use memory -- I am quite sure you have misunderstood something.


const char MyArray [300] [50] =

{

{" string1"},

{" string2"},

....

{" string300"}

};


棘手的部分是我需要将MyArray转换为char **所以我可以把它放在一个列表框中。


所以问题仍然存在,如何将MyArray转换为char **?
const char MyArray [300][50] =
{
{"string1"},
{"string2"},
....
{"string300"}
};

The tricky part is I need to convert MyArray to a char** so I can put
it in a listbox.

So the question still remains, how do I convert MyArray to a char**?



分配一个包含300个指针的数组A.初始化指针指向字符串

。 A的第一个元素的地址是你的char **。


-

答:因为它弄乱了人们通常阅读文本的顺序。

问:为什么这么糟糕?

A:热门发布。

问:什么是最烦人的事情usenet和电子邮件?

Allocate an array A of 300 pointers. Initialize the pointers to point
to the strings. The address of the first element of A is your char**.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


这篇关于char **问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆