我想将以上实例代码改成用c语言写的代码
时间: 2024-04-09 10:32:53 浏览: 39
好的,以下是用C语言编写的员工管理系统的示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_EMPLOYEES 100
typedef struct {
char name[50];
int age;
char position[50];
float salary;
} Employee;
typedef struct {
Employee employees[MAX_EMPLOYEES];
int count;
} EmployeeManagementSystem;
void add_employee(EmployeeManagementSystem *ems, Employee employee) {
if (ems->count < MAX_EMPLOYEES) {
ems->employees[ems->count++] = employee;
printf("Employee added successfully!\n");
} else {
printf("Employee database is full!\n");
}
}
void remove_employee(EmployeeManagementSystem *ems, char *name) {
int i, index = -1;
for (i = 0; i < ems->count; i++) {
if (strcmp(ems->employees[i].name, name) == 0) {
index = i;
break;
}
}
if (index != -1) {
for (i = index; i < ems->count - 1; i++) {
ems->employees[i] = ems->employees[i + 1];
}
ems->count--;
printf("Employee removed successfully!\n");
} else {
printf("Employee not found!\n");
}
}
void modify_employee_info(EmployeeManagementSystem *ems, char *name, int age, char *position, float salary) {
int i;
for (i = 0; i < ems->count; i++) {
if (strcmp(ems->employees[i].name, name) == 0) {
ems->employees[i
阅读全文