按工号或姓名查询
void searchNumberOrName()
{
int choice,number,i;
char name[50];
printf("\n请选择查询方式:\n");
printf("1. 按工号查询\n");
printf("2. 按姓名查询\n");
printf("请选择:");
scanf("%d", &choice);
if (choice == 1)
{
printf("请输入工号:");
scanf("%d", &number);
for (i = 0; i < num; i++)
{
if (employees[i].number == number)
{
printf("\n");
print(employees[i]);
return;
}
}
printf("未找到该职工!\n");
}
else if (choice == 2)
{
printf("请输入姓名:");
scanf("%s", name);
for (i = 0; i < num; i++)
{
if (strcmp(employees[i].name, name) == 0)
{
printf("\n");
print(employees[i]);
return;
}
}
printf("未找到该职工!\n");
}
else
{
printf("无效的选择!\n");
}
menu();
}
按部门查询
void searchDepartment()
{
int i,found = 0;
char department[50];
printf("请输入部门:");
scanf("%s", department);
for (i = 0; i < num; i++)
{
if (strcmp(employees[i].department, department) == 0)
{
print(employees[i]);
found = 1;
}
}
if (!found)
{
printf("未找到该部门的职工!\n");
}
system("pause");
system("cls");
menu();
}