[求助]改“职工管理信息系统”谢谢!
#include<stdio.h>#include<string.h>
#include<stdlib.h>
#include<conio.h>
typedef struct twrs{
char num[20];
char name[20];
char sex;
union
{
char position[20];
char degree;
int salary;
}
struct birth{
int year,month;
};
struct addr
{
char tel[12];
char addr[50];
};
}tea[20];
void Data_input(int j)
{ FILE *fp;
int j;
printf("Get ready to enter teacher_workers news:\n");
for(j=0;j<20;j++)
{ printf("num:");
scanf("%s",tea[j].num);
printf("name:");
scanf("%s",tea[j].name);
printf("sex:");
scanf("%s",tea[j].sex);
printf("year:");
scanf("%s",tea[j].birth.year);
printf("month:");
scanf("%s",tea[j].birth.month);
printf("degree:");
scanf("%s",tea[j].degree);
printf("position:");
scanf("%s",tea[j].position);
printf("salary:");
scanf("%s",tea[j].salary);
printf("addre:");
scanf("%s",tea[j].addr.addr);
printf("tel:");
scanf("%s",tea[j].addr.tel);
}
printf("end!\n");
fp=fopen("teacher_workers","w");
for(j=0;j<4;j++)
fwrite(&tea[j].sizeof(struct twrs),1,fp);
fclose(fp);
}
void print_News(struct teacher *p)
{ int i;
printf(“\n”);
for(i=1;i<=n;i++)
{ printf(“%5d”,(*(p+i)).num);
printf(“%20s”,(*(p+i)).name);
printf(“%3c”,(*(p+i)).sex);
printf(“%3d”,(*(p+i)).year);
printf(“%3d”,(*(p+i)).month);
printf(“%3c”,(*(p+i)).degree);
printf(“%3d”,(*(p+i)).position);
printf(“%3c”,(*(p+i)).salary);
printf(“%3c”,(*(p+i)).addr);
printf(“%3c”,(*(p+i)).tel);
}
}
void sort_with_num(int x[],int y[])
{ int k,t,i,j;
for(i=1;i<n;i++)
{ k=i;
for(j=i+1;j<n+1;j++)
if(x[j]>x[k]) k=j;
if(k!=i)
{ t=x[k];x[k]=x[i];x[i]=t;t=y[k];y[k]=y[i];y[i]=t; }
}
}
void write(struct tea stab[],unsigned numbers)
{
int i;
for(i=0;i<numbers;i++)
printf("%-ld\t%-12s\t%-d\t%-ld\t%-ldt%-ld\t%-d\t%-d\t%-d%\t%-d-0.2f\n",
stab[i] .num,stab[i].name,stab[i].sex,stab[i].year,stab[i].month,stab[i].
degree,stab[i].position,stab[i].salary,stab[i].addr,stab[i].tel \n");
}
void Data_save() {
int j;
fp=fopen(“teacher.txt”,”w”);
for(j=1;j<=i;j++)
{
fwrite(&teachers[j],sizeof(struct teacher),1,fp);
}
}
select()
{
char s[80];
int c;
clrscr();
printf("\n\n\n.....main menu.....\n\n\n");
printf("*1.input* 2.print*\n");
printf("*3.sort* 4.search*\n");
printf("*5.save* 6.exit*\n");
printf("***********\n");
do{
printf("\n\n\n select:");
gets(s);
c=atoi(s);
}while(c<0||c>6);
puts(s);
return(c);
}
void main()
{ char *name;
struct ters;
for( ; ;)
{
switch(select())
{ case 1:input();
break;
case 2:print_News();
break;
case 3:sort_with_num();
write();
break;
case 4:
printf(“\n\t please input name:”);
gets(search_name);
for(j=1;j<=I;j++)
{
if(strcmp(search_name,teachers[j].name)==0) )
{
print_News(*p);
break;
}
}
if(j>i)
printf(“\n\t No such records”);
}
break;
case 5:Data_save();
break;
case 6:exit(o);
}
}
}