#include<stdio.h>
#include<stdlib.h>
typedef struct {
char name[20];
char title[20];
char ssnum[20];
double salary;
int witholding ;
} employeeRecordT;
typedef struct {
int num;
employeeRecordT **info;
} *payrollT;
payrollT Getpayroll(payrollT result)
{
int i;
result = (payrollT) malloc(sizeof(payrollT));
scanf("%d",&result->num); // 输入员工个数
result->info = (employeeRecordT **) malloc(sizeof(employeeRecordT*) * result->num );
//使得info指向一个包含result->num个元素的指针数组。
for(i=0;i<result->num;i++)
{
result->info[i]= (employeeRecordT *) malloc(sizeof(employeeRecordT));
printf ("%d:",i+1);
//输入每个员工信息
scanf("%s%s%s%lf%d",result->info[i]->name,
result->info[i]->title,
result->info[i]->ssnum,
&result->info[i]->salary,
&result->info[i]->witholding);
}
return result;
}
int main()
{
int i;
payrollT emp;
emp = Getpayroll(emp);
//输出
printf("How many employees: %d\n",emp->num);
for ( i = 0; i < emp->num ;
i++)
{
printf("Employee #%d\n",i+1);
printf("
Name: %s\n",emp->info[i]->name);
printf("
Title: %s\n",emp->info[i]->title);
printf("
SSNum: %s\n",emp->info[i]->ssnum);
printf("
Salary: %.2lf\n",emp->info[i]->salary);
printf("
Withholding exemptions: %d\n",emp->info[i]->witholding);
}
return 0;
}