Help with struct

J

John Gerrard

Hi, this is my second week in C and this group.

This code compiles cleanly.

//a bit of this is copied from
//page 133 of K&R, 2nd edition
struct key
{
char *word;
int count;
} keytab[]=
{
{"auto",0},
{"break",0}
};


My code, which represents what I want to do, does not. I am sure it is
a syntax problem but could someone guide me on the type of syntax I
should use. My code for the structure is below.

struct teststr
{
char *word;
int[][] array;
} test[]=
{
{"1",{{1,2,3},{4,5,6},{7,8,9}},
{"2",{{1,2,3},{4,5,6}}
};

I don't want you to think I am lazy and not coding this myself. So here
is what I think. I can't have variable length arrays in the struct. I
think my approach should create a struct so that "array" is a pointer
to each of the variable length arrays so that each element in array
"test" is the same size. I would appreciate someone confirming this or
putting me on the right track, (and if it's difficult, a bit of
pseudocode so I get there).

Thank you again
John
 
R

Richard Heathfield

John Gerrard said:

struct teststr
{
char *word;
int[][] array;

K&R, 2nd edition, page 112, sentence beginning "More generally", about four
or five lines from the bottom.
 
J

John Gerrard

"More generally, only the first dimension(subscript) of an array is
free; all the others have to be specified. Section 5.12 has a further
discussion..."

Thanks
John


Richard said:
John Gerrard said:

struct teststr
{
char *word;
int[][] array;

K&R, 2nd edition, page 112, sentence beginning "More generally", about four
or five lines from the bottom.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top