#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
// 定义结构体
struct Paid
{
char work_num[10];
char work_name[20];
char work_part[50];
int work_paid;
int work_age;
};
//定义包含有Paid结构体的链表
typedef struct PaidList
{
struct Paid p;
struct PaidList* next;
} *pList;
//*******************************************************************
//将所有职工信息按工资多少排序
void sort(pList pl)
{
pList cur=pl;
pList temp;
pList next=pl->next;
temp=(pList)malloc(sizeof(struct PaidList));
while(cur->next!=NULL)
{
while(next!=NULL)
{
if(cur->p.work_paid<next->p.work_paid)
{
temp->p=cur->p;
cur->p=next->p;
next->p=temp->p;
}
next=next->next;
}
cur=cur->next;
next=cur->next;
}
}
//****************************************************************
//*****************************************************************
//输入职工信息
void shuru()
{
// 定义文件类型指针
FILE *fp;
//声明两个pList链表
pList list,next;
char f;
//初始化链表
list=(pList)malloc(sizeof(struct PaidList));
list->next=NULL;
next=list;
//清屏
system("cls");
//打开文件
fp=fopen("paid.txt","r");
if(!fp)
{
printf("不能打开文件");
}
//如果文件已存在,将文件中的已有数据读入链表中
if(fp)
{
while(feof(fp)==0)
{
fscanf(fp,"%s\t%s\t%s\t%d\t%d\n",next->p.work_num ,next->p.work_name,next->p.work_part,&next->p.work_paid,&next->p.work_age);
//如果文件指针未到末尾,将链表增加一个节点
if(!feof(fp))
{
next->next=(pList)malloc(sizeof(struct PaidList));
next=next->next;
next->next=NULL;
}
}
}
fclose(fp); //关闭文件流
if(!(fp=fopen(
职工信息管理(C语言实现)
最新推荐文章于 2022-06-05 11:49:20 发布
这个C语言程序实现了一个职工信息管理系统,包括职工信息录入、按工资排序、显示所有职工信息、按姓名、工号和部门查询以及计算平均工资等功能。通过结构体存储职工信息,并使用链表进行数据管理。
摘要由CSDN通过智能技术生成