473,831 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
+ 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 19904
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*******@aust in.rr.com> wrote in message
news:3F******** ******@austin.r r.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******** *********@twist er.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
4661
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 month I had enough of extra proof that the cat doesn't hount mice anymore in more and more situations. And the surrent sicretisme among array and hash is the base for it. I summarized all points in this article:...
7
7420
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
7102
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 string literal.
7
2542
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
4843
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 array notation, but is it really its own thing? You can declare arrays this way, can't you? An object in Javascript is like a hash array that stores pointers to properties and methods? Or is object literal notation a convenience form, wholly...
7
3802
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 access members by writing either of the two. obj.memberName
14
2363
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 pass the array as argument with no other info like number of strings. Is there a way to achieve that?
10
1611
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. I thought I could also do the following:
2
2519
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 the array is an object itself but what is this syntax of the consecutive double quotes inside the brackets ?
6
3873
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 there any way to do this with a variable length array? I've only been able to get it to work with a fixed size array. The relevant code snippets are below. Suggestions are greatly appreciated
0
9793
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
10777
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
9317
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6951
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5619
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...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4416
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
3963
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
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.