array of structures

Started by
3 comments, last by Densun 23 years, 11 months ago
I''m having trouble creating an array of structures. Here''s what I''m doing: typedef struct test_s { char* name; long id; } test_t; test_t tests[] = { { "name", 16 } }; Here''s the errors I get from the compiler: ''initializing'' : cannot convert from ''char [10]'' to ''struct frameinfo_s''. No constructor could take the source type, or constructor overload resolution was ambiguous too many initializers. What easily overlooked mistake am I making?
Advertisement
here''s how I would do it:
typedef struct test_s
{
char* name;
long id;
} test_t, *test_t_ptr;

test_t ARRAY[10];
ARRAY.name="name";
ARRAY.id=16;
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
While I could go:

test_t tests[x]; // Where x is any number.

tests[0].name = "name";
tests[0].id = 1;
.... // Repeat until whole array is filled.

It''s easier to assign the values in the declartion. That way I don''t have to continually write the name of the structure and the variables.

I still need help as to why it doesn''t work. I know it can, becuase I''ve seen code that does the same thing which works.
Your error message says "struct frameinfo_s" but the struct you''re showing is test_s. Besides, your code compiles in my compiler, but it is a c++ compiler, that could have something to do with it, I don''t code c.
A polar bear is a rectangular bear after a coordinate transform.
Ooops! I forgot to mention that the structure name and fields aren''t the same as my real code, I was just giving an overview of what I was doing. Also, my compiler supports C/C++.

This topic is closed to new replies.

Advertisement