/* Employee.h */
#ifndef EMPLOYEE_H_
#define EMPLOYEE_H_
typedef struct EmployeeImpl* Employee;
Employee Employee_Create(const char* name, int age);
void Employee_Delete(Employee e);
const char* Employee_GetName(Employee e);
int Employee_GetAge(Employee e);
#endif
/* main.c */
#include <stdio.h>
//#include "Employee.h"
int main(void)
{
Employee employees[2];
int i;
employees[0] = Employee_Create("Yamada", 25);
employees[1] = Employee_Create("Tanaka", 48);
for (i=0; i<sizeof(employees)/sizeof(Employee); i++) {
printf("Name: %s, Age: %d\n", Employee_GetName(employees[i]),
Employee_GetAge(employees[i]));
Employee_Delete(employees[i]);
}
return 0;
}
/* Employee.c */
#include <stdlib.h>
#include <string.h>
//#include "Employee.h"
typedef struct EmployeeImpl {
char name[256];
int age;
} EmployeeImpl;
Employee Employee_Create(const char* name, int age)
{
Employee e = (Employee)malloc(sizeof(EmployeeImpl));
strncpy(e->name, name, sizeof(e->name));
e->age = age;
return e;
}
void Employee_Delete(Employee e)
{
free(e);
}
const char* Employee_GetName(Employee e)
{
return e->name;
}
int Employee_GetAge(Employee e)
{
return e->age;
}
LyogRW1wbG95ZWUuaCAqLwojaWZuZGVmIEVNUExPWUVFX0hfCiNkZWZpbmUgRU1QTE9ZRUVfSF8KCnR5cGVkZWYgc3RydWN0IEVtcGxveWVlSW1wbCogRW1wbG95ZWU7CkVtcGxveWVlIEVtcGxveWVlX0NyZWF0ZShjb25zdCBjaGFyKiBuYW1lLCBpbnQgYWdlKTsKdm9pZCBFbXBsb3llZV9EZWxldGUoRW1wbG95ZWUgZSk7CmNvbnN0IGNoYXIqIEVtcGxveWVlX0dldE5hbWUoRW1wbG95ZWUgZSk7CmludCBFbXBsb3llZV9HZXRBZ2UoRW1wbG95ZWUgZSk7CgojZW5kaWYKCi8qIG1haW4uYyAqLwojaW5jbHVkZSA8c3RkaW8uaD4KLy8jaW5jbHVkZSAiRW1wbG95ZWUuaCIKCmludCBtYWluKHZvaWQpCnsKICBFbXBsb3llZSBlbXBsb3llZXNb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