473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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 4395
On 8 Apr, 20:00, Piotrek <nore...@noreply.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
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
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)...
19
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
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 =...
2
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...
5
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
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...
2
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...
17
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...
33
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.