|
-
October 4th, 2002, 10:57 AM
#1
explicitly defining each member of an array of structs
How would I make an array of structs then explicitly define each member of each struct in the array? For example:
Code:
struct test
{
char member1;
char member2;
};
typedef test array[2];
array real_var={
{ a, b }
{ c, d }
};
This obviously isn't right, any help or suggestions?
-
October 4th, 2002, 11:05 AM
#2
Hello there. You are very close:
Code:
struct test
{
char member1;
char member2;
};
typedef test array[2];
array real_var={
{ 'a', 'b' },
{ 'c', 'd' }
};
To initialize a struct, you just initialize each of its members in a
comma-separated list ... all within curly brackets. The same thing
is done with arrays. That's why you see a comma between the
first struct and the second struct.
The only other problem you had was not putting apostrophes
around your char's. The way to specify a char data type is to
put apostrophes around them; that's why you see 'a', 'b', etc....
--Paul
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|