I need to be able to to store two strings in a structure and then have 10000 of these structures. Is there a way to do this?
I need to be able to to store two strings in a structure and then have 10000 of these structures. Is there a way to do this?
Yes. Here is one way:DavidCode:struct MyStruct { char String_One[255]; char String_Two[255]; }; MyStruct myStruct[10000];
One Ring to rule them all, One Ring to find them,
One Ring to bring them all and in the darkness bind them
In the Land of Mordor where the Shadows lie.
If you have basic knowledge in pointers:
This method is great if you want to decide how many structures you want when running the program, not just when compiling.Code:typedef struct { char String_One[255]; char String_Two[255]; }MyStruct; MyStruct* pObject; int NumberOfElements=10000; pObject=new MyStruct[NrOfElements]; ... delete[] pObject;
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
typedef unsigned char BYTE;
Simple array of structures
struct RGB
{
BYTE red;
BYTE grn;
BYTE blu;
BYTE alpha;
};
RGB *Palette=new RGB[255];
Complex array of structures
struct Point
{
int x;
int y;
};
struct Vertex
{
double x;
double y;
double z;
};
struct Coord
{
Vertex Local;
Vertex World;
Vertex Aligned;
Point Screen;
RGB color;
};
Coord *Object=new Coord[numvertexes];
Can also be done with classes.
Oooooooops!!! Hate it when the subject of the post does not exactly match the question. But, ........uh..........yes you can create arrays of structures.