473,657 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

array of array of pointers

Hi there again!
Last time you helped me with pointers - it let me to save many hours of
searching for some solutions. And once again I have question.
Let's declare array of pointers:

char *O={"", "one", "two",..., "eighteen"} ;
char *T={"", "ten", "twenty",.. ., "eighty"};

And now I want to declare an array of arrays of pointers:
something like:

char A={O,T};

Compiler says: "error C2440: 'initializing' : cannot convert from 'char
*[10]' to 'char'".
Here we go with first question: How to declare such array?

The point is that I want to refer to ie. "one" (O[1]) by something like
A[0][1];
That's my second question: How to refer to "one" by array A?

I hope you understand what I mean ... :)

Thank you in advance!!!
BTW
I couldn't find it in FAQ
And, please, feel free to correct my English!
--
Piotrek
Apr 8 '07 #1
6 4412
On 8 Apr, 20:00, Piotrek <nore...@norepl y.comwrote:
Last time you helped me with pointers - it let me to save many hours of
searching for some solutions. And once again I have question.
Let's declare array of pointers:

char *O={"", "one", "two",..., "eighteen"} ;
char *T={"", "ten", "twenty",.. ., "eighty"};
This is a compile time error. {"", "one", ...}
is an array of char *, so the type should be
char *O[];
And now I want to declare an array of arrays of pointers:
something like:

char A={O,T};
How to declare such array?
Something like this...

#include <stdlib.h>
#include <stdio.h>

int
main( void )
{
char *O[] = {"", "one", "two", "eighteen"} ;
char *T[] = {"", "ten", "twenty", "eighty"};
char **A[2];
A[0] = O;
A[1] = T;

printf( "%s\n", A[0][2]) ;
return EXIT_SUCCESS;
}

Apr 8 '07 #2
[...]
char A={O,T};
[...]
I mean char A[]={O,T};

Or maybe I should declare array of pointers to array of pointers, but it
still fails to compile:
char *A[]={O,T};

--
Piotrek
Apr 8 '07 #3
Piotrek wrote:
Hi there again!
Last time you helped me with pointers - it let me to save many hours of
searching for some solutions. And once again I have question.
Let's declare array of pointers:

char *O={"", "one", "two",..., "eighteen"} ;
char *T={"", "ten", "twenty",.. ., "eighty"};
Is this what you actually wrote? The compiler should
have complained about it, because the initializers do not
match the things being initialized. I'll assume you wrote
something more like

char *O[] = { "", "one", ... };

.... which agrees better with the initializer and with the
samples you show below.
And now I want to declare an array of arrays of pointers:
something like:

char A={O,T};

Compiler says: "error C2440: 'initializing' : cannot convert from 'char
*[10]' to 'char'".
Here we go with first question: How to declare such array?
One way is

char **A[] = { O, T };
The point is that I want to refer to ie. "one" (O[1]) by something like
A[0][1];
That's my second question: How to refer to "one" by array A?
[...]
BTW
I couldn't find it in FAQ
Thanks for checking. Even though it's not exactly what
you're looking for, Question 1.21 may be helpful.

--
Eric Sosman
es*****@acm-dot-org.invalid
Apr 8 '07 #4
Eric Sosman wrote:
[...]
>char *O={"", "one", "two",..., "eighteen"} ;
char *T={"", "ten", "twenty",.. ., "eighty"};

Is this what you actually wrote? The compiler should
have complained about it, because the initializers do not
match the things being initialized. I'll assume you wrote
something more like

char *O[] = { "", "one", ... };
Of course I wrote char *O[]=... I made mistake writing a post. I see you
read very carefully - thanks!

[...]
One way is

char **A[] = { O, T };
>The point is that I want to refer to ie. "one" (O[1]) by something
like A[0][1];
[...]
Thanks for checking. Even though it's not exactly what
you're looking for, Question 1.21 may be helpful.
This is EXACTLY what I'm looking for, thanks a lot!

--
Piotrek
Apr 8 '07 #5
Piotrek wrote:
[...]
Of course I wrote char *O[]=... I made mistake writing a post. I see you
read very carefully - thanks!
<off-topic>

General observation, not specific to C: A programmer either
develops an eye for detail, or develops a different career.

Computers are very obedient, and have a nasty tendency to do
what you tell them instead of what you meant to tell them.

</off-topic>

--
Eric Sosman
es*****@acm-dot-org.invalid
Apr 8 '07 #6
Piotrek wrote:

Of course I wrote char *O[]=... I made mistake writing a post. I see
you read very carefully - thanks!

That's exactly why we request that you cut and past the EXACT program
that you have. Not something like it. Not the code retyped. No missing
pieces. No ... to show stuff left out.

The. Exact. Program.
Learn that. Embrace that. Live that.


Brian
Apr 8 '07 #7

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

Similar topics

14
8473
by: dam_fool_2003 | last post by:
Friends, cannot we malloc a array? So, I tried the following code: int main(void) { unsigned int y={1,3,6},i,j; for(i=0;i<3;i++) printf("before =%d\n",y); *y = 7; /* 1*/
20
2941
by: fix | last post by:
Hi all, I feel unclear about what my code is doing, although it works but I am not sure if there is any possible bug, please help me to verify it. This is a trie node (just similar to tree nodes) struct, I am storing an array of 27 pointers and a void pointer that can point to anything. typedef struct trieNode { struct trieNode *children; // The children nodes void *obj; // The object stored } TrieNode;
19
14509
by: gaga | last post by:
I can't seem to get this to work: #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *names; char **np;
204
12984
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 = {0,1,2,4,9};
2
2124
by: Simon Morgan | last post by:
I hope this isn't OT, I looked for a newsgroup dealing purely with algorithms but none were to be found and seeing as I'm trying to implement this in C I thought this would be the best place. I have an array of structs containing data which I'd like to output ordered based on the value of a single member. I was wondering if there is a relatively simple way of doing this without actually modifying the structure of the array? I had a...
5
3123
by: Paminu | last post by:
Why make an array of pointers to structs, when it is possible to just make an array of structs? I have this struct: struct test { int a; int b;
17
7239
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?
2
2974
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your standard dynamic address book program. Adding, and listing work just fine. However, deleting, editing and viewing relies on member function retAddress. This function returns an array of pointers that are pointing to created objects. In action, all it...
17
2313
by: Ben Bacarisse | last post by:
candide <toto@free.frwrites: These two statements are very different. The first one is just wrong and I am pretty sure you did not mean to suggest that. There is no object in C that is the same as its address. The second one simply depends on a term that is not well-defined. Most people consider the type to be an important part of the notion of
33
7162
by: Adam Chapman | last post by:
Hi, Im trying to migrate from programming in Matlab over to C. Im trying to make a simple function to multiply one matrix by the other. I've realised that C can't determine the size of a 2d array, so im inputting the dimensions of those myself. The problem is that the output array (C=A*B) has as many rows as A and as many columns as B. I would think of initialising C with:
0
8421
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
8325
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
8742
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...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
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
6177
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
5643
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();...
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
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.