#include #include // needed for malloc() #include // needed for strcpy() #define NAMLEN 32 /* we can define global constant symbols */ #define MAXCNT 3 /* the following structure defines a new type */ struct employee { char name[NAMLEN]; int id; float wage; }; /* function prototypes */ void print_employees(struct employee [], int); struct employee * get_employees(); int main(int argc, char* argv[]) { struct employee * staff; staff = get_employees(); print_employees(staff, MAXCNT); free(staff); // release the memory allocated in get_employees() return 0; } /* function definition */ void print_employees(struct employee staff[], int count) { int i; printf("There are a total of %d employees.\n"); for (i = 0; i < count; i ++) { printf("Information for employee [%d] : \n", i); printf(" name : %s\n", staff[i].name); printf(" id : %d\n", staff[i].id); printf(" wage : $%10.2f\n", staff[i].wage); } } /* function definition */ struct employee * get_employees() { // struct employee * e = malloc(sizeof(struct employee)); struct employee * people = (struct employee *)malloc(MAXCNT * sizeof(struct employee)); strcpy(people[0].name, "John Smith"); people[0].id = 0; people[0].wage = 123456; strcpy(people[1].name, "Jane Doe"); people[1].id = 1; people[1].wage = 234567; strcpy(people[2].name, "Alice Wonderland"); people[2].id = 2; people[2].wage = 345678; return people; }