473,654 Members | 3,104 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

char** question...

RAB
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

Aug 6 '06 #1
15 1810
* RAB:
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"}
}
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.

I need to build a function that will return MyArray in the form of a
char**
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.

--
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?
Aug 6 '06 #2
RAB
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

Aug 7 '06 #3
* RAB:
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.

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.
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" }
};

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**?
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?
Aug 7 '06 #4

RAB wrote:
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**?
I think this maybe what you want:

char (*ptr)[50] = MyArray;

Aug 7 '06 #5
RAB posted:
I need to build a function that will return MyArray in the form of a
char**

Here's a little sample code I cooked up with might be of help:

#include <iostream>
using std::cout;

unsigned const quantity_names = 50;

char const *const *GetNames()
{
/* Returns a null-terminated
array of pointers to strings. */

char const static *const arr[quantity_names] = {
"Adam", "Paul", "Philip", "James", "Matthew",
"Brian", "Thomas", "Mary", "Sandra", "Kelly",
"Lisa", "Heather" };

return arr;
}

int main()
{
for(char const *const *p = GetNames(); *p; ++p)
{
cout << *p << '\n';
}
}

--

Frederick Gotham
Aug 7 '06 #6
RAB

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.
Belive it or not, the Palm OS uses 16 bit addresses, it is quite
archaic. It makes programming a challenge. It makes one appreciate
CStrings in the Microsoft architecture.
Allocate an array A of 300 pointers.
Could you share some code please?
>Initialize the pointers to point to the strings.
Could you share some code please?

I am a hobbiest programmer and char arrays have always been a challenge
for me.

Thanks,
RABMissouri

Aug 7 '06 #7
RAB
Hello Sun,

char (*ptr)[50];
compiles ok
char (*ptr)[50]=MyArray;
compiler error "illegal implicit conversion from 'const
char[300][50]' to 'char (*)[50]'

Also, inorder to copy char* one must use
StrCopy(Char *dst, const Char * src); //function definition

Thanks,
RABMissouri

Aug 7 '06 #8
RAB
Hi Frederick,

Thanks for you help! Your code looks great.

MyArray has already been created. So I need to create a char** from
MyArray.

Another thing I should have told you, is inorder to copy arrays I need
to use the function
StrCopy( Char *dst, const Char *src);

Thanks,
RABMissouri

Aug 7 '06 #9
* RAB:
>
>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.

Belive it or not, the Palm OS uses 16 bit addresses, it is quite
archaic. It makes programming a challenge. It makes one appreciate
CStrings in the Microsoft architecture.
?

>Allocate an array A of 300 pointers.
Could you share some code please?
char* pointers[300];

>Initialize the pointers to point to the strings.
Could you share some code please?
No, this smells like homework. Use a loop. If you have any problems,
post your code and describe exactly what the problem is.

I am a hobbiest programmer and char arrays have always been a challenge
for me.
--
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?
Aug 7 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
69403
by: Nicholas Parnell | last post by:
Hi! I have the problem where I cast a bit string of "10000000" to a byte, which i get -128; this is fine so far. However, when I take this byte and cast it to a char, I get a question mark('?'). So when i go to cast it back to a byte, i now get 63 (the ascii representation of a question mark). I see that for any byte from 128 to 256 i'll get a question mark... must be java's way of indicating that's it's negative or something.... my...
8
6174
by: Ekim | last post by:
my question is as follows: I've got a DLL in which I have a method GetBuffer (this one is extern, exported, is called from outside this program) which shall pass a char-buffer to the calling-function for further handling. If I've confused you, here's the code snippet (it's within a simple Win32-Dll-project): char* buffer; // global buffer - this one points to my buffer (for puttiing it simple in here I assume memory is already...
19
2392
by: Jasper Dozer | last post by:
Is this a healthy way to get a pointer to point ? char *p = "longenough"; regards, jasper
1
2825
by: b83503104 | last post by:
When are they not consistent?
42
32146
by: S S | last post by:
Hi Everyone I have const char *p = "Hello"; So, here memory is not allocated by C++ compiler for p and hence I cannot access p to modify the contents to "Kello" p = 'K'; // error at runtime
7
2138
by: owolablo | last post by:
Can anybody please tell me how to change the individual elements of a char variable. I need to parse through the string, check for a particular character and change it to something else if it is found. Thanks
9
2255
by: happyvalley | last post by:
I just wonder how to pass arguments to this function with a char** void oldmain(int argv, char**argc) { ........ } void main(void) { int argv;
12
9389
by: karthikbalaguru | last post by:
Hi, How is 'Int' Faster than 'Char' ? I think , 'Char' is small and so it should be easily & efficiently . Can someone here provide some info regarding this. Thanks and Regards, Karthik Balaguru
43
17198
by: emyl | last post by:
Hi all, here's an elementary question. Assume I have declared two variables, char *a, **b; I can then give a value to a like a="hello world";
16
1640
by: MN | last post by:
I have a question : How to understand the mean of char** type ?
0
8379
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8294
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8709
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8596
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2719
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1597
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.