I want an initializer for an array of pointers to arrays of strings.
So I can do something like this:
const char *t1[] = { "a", "b", "c", NULL };
const char *t2[] = { "p", "q", NULL };
const char *t3[] = { "w", "x", "y", "z", NULL };
const char **test[] = { t1, t2, t3, NULL };
I was wondering whether the is a more elegant way of writing such an
initializer, one that does away with all the redundant names t1, t2, etc.
For a 2d array of strings I could do:
const char *test2[][5] =
{
{ "a", "b", "c", NULL, NULL },
{ "p", "q", NULL, NULL, NULL },
{ "w", "x", "y", "z", NULL }
};
Is there something similar for arrays of pointers to arrays of strings? 2 7179
Steve wrote: I want an initializer for an array of pointers to arrays of strings.
So I can do something like this:
const char *t1[] = { "a", "b", "c", NULL }; const char *t2[] = { "p", "q", NULL }; const char *t3[] = { "w", "x", "y", "z", NULL }; const char **test[] = { t1, t2, t3, NULL };
I was wondering whether the is a more elegant way of writing such an initializer, one that does away with all the redundant names t1, t2, etc.
For a 2d array of strings I could do:
const char *test2[][5] = { { "a", "b", "c", NULL, NULL }, { "p", "q", NULL, NULL, NULL }, { "w", "x", "y", "z", NULL } };
Is there something similar for arrays of pointers to arrays of strings?
Will this do?
int main(void)
{
const char **test[] = { (const char *[]) {"a", "b", "c", 0},
(const char *[]) {"p", "q", 0},
(const char *[]) {"w", "x", "y", "z", 0},
0 };
return 0;
}
--
Martin Ambuhl
Martin Ambuhl wrote: Will this do?
int main(void) { const char **test[] = { (const char *[]) {"a", "b", "c", 0}, (const char *[]) {"p", "q", 0}, (const char *[]) {"w", "x", "y", "z", 0}, 0 }; return 0;
Yes, thanks, that does do the trick.
I notice that my C compiler is ok with it, but my C++ one not. Curious, but
that would be a question for another group.
Thanks again,
Steve This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steve |
last post by:
I want an initializer for an array of pointers to arrays of strings.
So I can do something like this:
const char* t1 = { "a", "b", "c", 0 };
const char* t2 = { "p", "q", 0 };
const char* t3 = { "w", "x", "y", "z", 0 };
const char* const* test = { t1, t2, t3, 0 };
I was wondering whether the is a more elegant way of writing such an
|
by: hokieghal99 |
last post by:
I wish to place all files and directories that are within a user defined
path (on a Linux x86 PC) into some type of array and then examine those
items for the existence of certain charaters such as "*?<>/\|\\" If one
of the chars are found, I'd like to replace it with a "-" and then
commit the change to the actual file system. I know that a scripting
language may be better suited for this, but I'm experimenting with C and
I'm trying to...
|
by: Simon Schaap |
last post by:
Hello,
I have encountered a strange problem and I hope you can help me to
understand it. What I want to do is to pass an array of chars to a
function that will split it up (on every location where a * occurs in
the string). This split function should allocate a 2D array of chars
and put the split results in different rows. The listing below shows
how I started to work on this. To keep the program simple and help
focus the program the...
|
by: David Mathog |
last post by:
This one is driving me slightly batty. The code in question is
buried deep in somebody else's massive package but it boils down to
this, two pointers are declared, the first is:
char **resname
which is part of the "atoms" structure that is passed into the function
from the outside. I have not yet found where it is allocated but I'm
reasonably sure from other chunks of this code that it was by:
|
by: sandy |
last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory',
within my class Directory (Can you already smell disaster?)
Each Directory can have subdirectories so I thought to put these in an
array. The application compiles but aborts without giving me any useful
information.
What I suspect is happening is infinite recursion. Each Directory
object creates an array of Subdirectories each of which has an array of...
| |
by: Marvin Barley |
last post by:
I have a class that throws exceptions in new initializer, and a static
array of objects of this type.
When something is wrong in initialization, CGI program crashes
miserably. Debugging shows uncaught exception.
How to catch an exception that happened before main() try { ... }
catch (...) { ... } block?
Is there a way?
|
by: copx |
last post by:
Unforuntately, I know next to nothing about ASM and compiler construction,
and while I was aware of the syntactic differences between pointers and
arrays, I was not aware of this:
http://udrepper.livejournal.com/13851.html
(Yes, it is livejournal, but it is the journal of the glibc maintainer)
I am not sure I really understand this low-level difference between pointers
and arrays, and I do not have the time to learn ASM and compiler...
|
by: JackYee123 |
last post by:
Hey,
I need a structure to store a string array in c, for example
Index Content
-------- -----------
0 word1
1 word2
2
3
|
by: =?Utf-8?B?U2hhcm9u?= |
last post by:
Hi Gurus,
I need to transfer a jagged array of byte by reference to unmanaged
function, The unmanaged code should changed the values of the array, and when
the unmanaged function returns I need to show the array data to the end user.
Can I do that?
How?
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |