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?
Printable View
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];
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;
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.:D