473,473 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

array of string literals

This doesn't compile:

const char** ids =
{
"aaa",
"bbb",
"ccc"
};

I hope the above illustrates what I am trying to do, if it is possible, what
is the correct syntax?

btw i want to create a static array where each element is a c-style array
(in case my example was unclear)
Jul 19 '05 #1
4 19889
Jeff Williams wrote:
This doesn't compile:

const char** ids =
const char * ids[] =
{
"aaa",
"bbb",
"ccc"
};

I hope the above illustrates what I am trying to do, if it is possible, what
is the correct syntax?

btw i want to create a static array where each element is a c-style array
(in case my example was unclear)

HTH,
--ag
--
Artie Gold -- Austin, Texas

Jul 19 '05 #2

"Artie Gold" <ar*******@austin.rr.com> wrote in message
news:3F**************@austin.rr.com...
Jeff Williams wrote:
This doesn't compile:

const char** ids =


const char * ids[] =
{
"aaa",
"bbb",
"ccc"
};

I hope the above illustrates what I am trying to do, if it is possible, what is the correct syntax?

btw i want to create a static array where each element is a c-style array (in case my example was unclear)

HTH,
--ag
--
Artie Gold -- Austin, Texas


Thanks, worked great!

Jeff
Jul 19 '05 #3

"Jeff Williams" <no*********************************@mfchelp.com > wrote in message
news:Bq*****************@twister.southeast.rr.com. ..
This doesn't compile:

const char** ids =


Learn the difference between a pointer and an array. The above is a pointer to
pointer. An array of pointers is:

const char* ids[] =
Jul 19 '05 #4
Jeff Williams wrote:
This doesn't compile:

const char** ids =
{
"aaa",
"bbb",
"ccc"
};

I hope the above illustrates what I am trying to do, if it is possible, what
is the correct syntax?

btw i want to create a static array where each element is a c-style array
(in case my example was unclear)


Your description of what you want doesn't match the solution you accepted.

const char *ids[] = { "aaa", "bbb", "ccc" };

This does not create an "array where each element is a c-style array."
(By the way, there's no "C++-style arrays", so you don't need to specify
C-style for an array. All arrays are C-style.) It creates an array where
each element is a pointer to a null-terminated character string. To get
what you described, you need something like this:

char ids[][N] = { "aaa", "bbb", "ccc" };

Where N is chosen to be large enough for your longest string (including
the null character).

As for making it static, it might depend on what exactly you mean by
that. Generally you just add the keyword 'static':

static char ids[][N] = { "aaa", "bbb", "ccc" };

But this has different meanings in different contexts, and the meaning
may not be the one you want.

If you meant "statically allocated" and the declaration is at namespace
or global scope, then you shouldn't need the 'static' at all. If the
declaration is in a function, you should add the 'static' keyword. If
the declaration is in a class, you need the 'static' and you also need a
separate definition outside the class, and you should move the
initializer to that definition.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #5

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

Similar topics

22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
7
by: Bo Sun | last post by:
hi: please take a look at the following code fragment: char* hello = "Hello World\n"; hello = 's'; why I cannot modify hello?
20
by: Petter Reinholdtsen | last post by:
Is the code fragment 'char a = ("a");' valid ANSI C? The problematic part is '("a")'. I am sure 'char a = "a";' is valid ANSI C, but I am more unsure if it is allowed to place () around the...
7
by: James Mcguire | last post by:
Hi, I frequently do non-initialisation type structure assignment via casting: e.g. struct s{int i,j,k;} mys; .... mys=(struct s){3,4,5};
6
by: Jake Barnes | last post by:
I was just reading this article on Ajaxian: http://ajaxian.com/archives/show-love-to-the-object-literal This is a newbie question, but what is the object literal? I thought it was like an...
7
by: Sam Kong | last post by:
Hello! My question would not be very practical but just out of curiosity. In JavaScript, Array is a subclass of Object. Well maybe not exactly... but sort of... For normal objects, you can...
14
by: ranjmis | last post by:
Hi all, Below is the code wherein I am initializing double dimentional array inside main with string literals. Now I want to display the strings using a function call to which I just want to...
10
by: futhark77 | last post by:
Hi, In a program, I can declare strings that way: char *some_str = "some string"; char *some_str2 = "some other string"; I will be able to work on them very naturally with strlen and such....
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
6
by: Arnshea | last post by:
(apologies for the crosspost) I'm working with an MFC based COM object. From C# I'd like to be able to call a method on the COM object that takes a string array and modifies the contents. Is...
0
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,...
0
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,...
0
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.