I'm try to make an payroll program in c++. In the beginning of my program I have to define a struct called EmployeeT that will store all the information about an employee together in one unit.
Then I have to take all that information and put it in an array of EmployeeT structures called employees.
I have this so far...
typedef struct
{
char name[];
char title;
double gross;
double tax;
double net;
} EmployeeT;
So, What am I miss or doing wrong?
Thanks guys
What you have there is fine, except that if you want a flexible array member (char name[]
), it needs to be the last field in the structure. Probably what you really want is a pointer (char *name
) or a real array (char name[SOME_SIZE]
), though.
When you declare char name[], you need to give it a length for the array if it is going to be static. Otherwise, declare it as a pointer so that you can dynamically create the array later.
The struct needs to know exactly how large it will be, so you can't have an array with unknown size inside it.
change char name[] to char name* .
when initializing use:
name = new name[SIZEOFARRAY];
and, when you dont need it anymore, dont forget to delete it:
delete [] name;
for example
struct stu
{
int num;
char name[20];
char sex;
float score;
};