/* * File: employee1.c * Creator: George Ferguson * * First version of a type representing employees. */ #include #include struct Employee { char* name; int id; }; struct Employee* new_Employee(char *name, int id) { struct Employee* this = (struct Employee*)malloc(sizeof(struct Employee)); if (this == NULL) { return NULL; // Out of memory... } this->name = name; // See text this->id = id; return this; } void Employee_print(struct Employee* this) { printf("Employee[%s,%d]", this->name, this->id); } int main(int argc, char* argv[]) { struct Employee* e1 = new_Employee("Alan Turing", 123); Employee_print(e1); struct Employee* e2 = new_Employee("Edsgar Dijkstra", 456); Employee_print(e2); struct Employee* e3 = new_Employee("Alan Kay", 789); Employee_print(e3); }