职工信息管理(C语言实现)

这个C语言程序实现了一个职工信息管理系统,包括职工信息录入、按工资排序、显示所有职工信息、按姓名、工号和部门查询以及计算平均工资等功能。通过结构体存储职工信息,并使用链表进行数据管理。
摘要由CSDN通过智能技术生成
#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(
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值