?? main.txt
字號:
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<stdio.h>
#include "graphics.h"
#include "conio.h"
#include "dos.h"
#define maxworker 100
/*漢字顯示程序*/
void *buffer;
FILE *al;
void hz(int x,int y,int a,int COL,int b,char *s)
{
int ROW;
char buffer[32];
register m,n,i,j,k;
unsigned char qh,wh;
unsigned long offset;
ROW=COL;
while(*s)
{
qh=*(s)-0xa0;
wh=*(s+1)-0xa0;
offset=(94*(qh-1)+(wh-1))*32L;
fseek(al,offset,SEEK_SET);
fread(buffer,32,1,al);
for (i=0;i<16;i++)
for(n=0;n<ROW;n++)
for(j=0;j<2;j++)
for(k=0;k<8;k++)
for(m=0;m<COL;m++)
if (((buffer[i*2+j]>>(7-k))&0x1)!=NULL)
putpixel(x+8*j*COL+k*COL+m,y+i*ROW+n,b);
s+=2;
x+=a;
}
}
FILE *fp; /*定義全局變量fp,指向數(shù)據(jù)庫文件 worker.txt*/
struct date1{ /*日期的結(jié)構(gòu),用于存儲工人的生日,工作日期等*/
int year;
int month;
int day;
};
struct address { /*地址的結(jié)構(gòu), 用于存儲工人的地址*/
char province[10];
char city[10];
char street[20];
};
struct WORKER { /*工人的資料總結(jié)構(gòu)*/
char name[20];
enum {male,female}sex;
struct date1 birthday;
enum {elesch,middle,high,university,other}rofs;
struct date1 workday;
int workeri;
char position[20];
struct address addr;
int workerj;
char tel[13];
};
/*程序的初始化函數(shù),用于從數(shù)據(jù)庫中讀出現(xiàn)存的資料到內(nèi)存中*/
void data_load(int *i,struct WORKER *p){
char c;
long int k;
fp=fopen("worker.txt","r");
if(!fp){fopen("worker.txt","w+");*i=0;}
else{
for((*i)=0;(*i)<maxworker;(*i)++){
if(feof(fp)) return;
c=fgetc(fp);
if(c==EOF) return;
fflush(stdin);
k=*i;
fseek(fp,k*sizeof(struct WORKER),SEEK_SET);
fread(&p[*i],sizeof(struct WORKER),1,fp);
}
}
fclose(fp);
}
/*添加一個工人的資料*/
void add(int *i,struct WORKER *profile){
char add_name[20],add_position[20],add_addr_province[20],add_addr_city[20],add_addr_street[30],add_tel[13];
int add_birthday_year,add_birthday_month,add_birthday_day,add_workday_year,add_workday_month,add_workday_day;
int add_sex,add_rofs;
enum {false,true}status;
status=false;
printf("\n\tNow add NO. %d worker's profile\n",*i+1);
/*以下是處理輸入的循環(huán)
其中status是個flag,用于指定是否有輸錯的地方,如果有的話,
立刻跳的最初的提示。
*/
while(status==false){
printf("Enter the name of the worker:");
scanf("%s",add_name);
if(strlen(add_name)==0 || strlen(add_name)>20){
status=false;puts("input error,name cannot over 8 character or less than 0 character!");
continue;
}
else
status=true;
printf("Enter the gender of worker:(1=>female,0=>male)");
scanf("%d",&add_sex);
if(add_sex!=0 && add_sex!=1){
status=false;puts("only 0 or 1 can be accepted!");
continue;
}
else
status=true;
printf("Enter the birthday of worker:\n");
printf("\tYear:");
scanf("%4d",&add_birthday_year);
if(add_birthday_year>9999 || add_birthday_year<0){
status=false;puts("input error,the year of birthday cannot more than 9999 or less than 0!");
continue;
}
else
status=true;
printf("\tMonth:");
scanf("%2d",&add_birthday_month);
if(add_birthday_month>12 || add_birthday_month<1){
status=false;puts("input error,the month of birthday cannot be more than 12 or less than 1");
continue;
}
else
status=true;
printf("\tDay:");
scanf("%2d",&add_birthday_day);
if(add_birthday_day>31 || add_birthday_day<1){
status=false;puts("input error,the year of birthday cannot be more than 31 or less than 1!");
continue;
}
else
status=true;
printf("Enter the workday of worker:\n");
printf("\tYear:");
scanf("%4d",&add_workday_year);
if(add_workday_year>9999 || add_workday_year<0){
status=false;puts("input error,the year of workday cannot more than 9999 or less than 0!");
continue;
}
else
status=true;
printf("\tMonth:");
scanf("%2d",&add_workday_month);
if(add_workday_month>12 || add_workday_month<1){
status=false;puts("input error,the month of workday cannot be more than 12 or less than 1");
continue;
}
else
status=true;
printf("\tDay:");
scanf("%2d",&add_workday_day);
if(add_workday_day>31 || add_workday_day<1){
status=false;puts("input error,the year of workday cannot be more than 31 or less than 1!");
continue;
}
else
status=true;
printf("Enter the record of formal schooling of worker:(0=>element school,1=>middle school,2=>high school,3=>university,4=>other)");
scanf("%d",&add_rofs);
if(add_rofs!=0 && add_rofs!=1 &&add_rofs!=2 &&add_rofs!=3 &&add_rofs!=4){
status=false;puts("only digit can be accepted!you can only enter 0,1,2,3,4");
continue;
}
else
status=true;
printf("Enter the position of worker:");
scanf("%s",add_position);
if(strlen(add_position)==0 || strlen(add_position)>20){
status=false;puts("input error,position cannot over 20 character or less than 0 character!");
continue;
}else
status=true;
printf("Enter the address of worker:\n");
printf("\tProvince:");
scanf("%s",add_addr_province);
if(strlen(add_addr_province)==0 || strlen(add_addr_province)>20){
status=false;puts("input error,province cannot over 20 character or less than 0 character!");
continue;
}
else
status=true;
printf("\tCity:");
scanf("%s",add_addr_city);
if(strlen(add_addr_city)==0 || strlen(add_addr_city)>20){
status=false;puts("input error,city cannot over 20 character or less than 0 character!");
continue;
}
else
status=true;
printf("\tStreet:");
scanf("%s",add_addr_street);
if(strlen(add_addr_street)==0 || strlen(add_addr_street)>30){
status=false;puts("input error,street cannot over 30 character or less than 0 character!");
continue;
}
else
status=true;
printf("Enter the telephone number of worker:(area code/telephone code)");
scanf("%s",add_tel);
if(strlen(add_tel)==0 || strlen(add_tel)>13){
status=false;puts("input error,telephone number cannot over 13 character or less than 0 character!");
continue;
}
else
status=true;
}
/*檢查完畢,開始將輸入的東西保存到結(jié)構(gòu)數(shù)組中*/
strcpy(profile[*i].name,add_name);
profile[*i].sex=add_sex;
profile[*i].birthday.year=add_birthday_year;
profile[*i].birthday.day=add_birthday_day;
profile[*i].birthday.month=add_birthday_month;
profile[*i].workday.year=add_workday_year;
profile[*i].workday.day=add_workday_day;
profile[*i].workday.month=add_workday_month;
profile[*i].rofs=add_rofs;
strcpy(profile[*i].position,add_position);
strcpy(profile[*i].addr.province,add_addr_province);
strcpy(profile[*i].addr.city,add_addr_city);
strcpy(profile[*i].addr.street,add_addr_street);
strcpy(profile[*i].tel,add_tel);
++(*i);
printf("\n\nin function add :i=%d\n\n",*i);
}
/*顯示所有的工人資料的列表*/
void list(int i,struct WORKER *prof){
int j;
char temp[20];
if(i==0){printf("There is no profile in the list!\nPress any key to return!\n");getch();return;}
printf("========There are %d workers' profiles========\n\n",i);
for(j=0;j<i;j++){
printf("NO. %d worker's profile=>\n",(j+1));
printf("\n\tName: %s\n",prof[j].name);
if(prof[j].sex)
strcpy(temp,"Female");
else
strcpy(temp,"Male");
printf("\tGender:%s\n",temp);
printf("\tBirthday:");
printf("%4d %2d %2d\n",prof[j].birthday.year,prof[j].birthday.month,prof[j].birthday.day);
printf("\tWorkday:");
printf("%4d %2d %2d\n",prof[j].workday.year,prof[j].workday.month,prof[j].workday.day);
switch(prof[j].rofs){
case 0:
strcpy(temp,"Element school");
break;
case 1:
strcpy(temp,"Middle school");
break;
case 2:
strcpy(temp,"High school");
break;
case 3:
strcpy(temp,"University");
break;
case 4:
strcpy(temp,"Other");
break;
default:
strcpy(temp,"Error");
}
printf("\tThe record of formal schooling:%s\n",temp);
printf("\tPosition:%s\n",prof[j].position);
printf("\tAddress:%s %s city %s province\n",prof[j].addr.street,prof[j].addr.city,prof[j].addr.province);
printf("\tTelephone number:%s\n",prof[j].tel);
getch();
}
}
/*顯示指定的工人的資料*/
void display(int dk,struct WORKER *prof){
char temp[20];
if(dk>maxworker)
return;
printf("\n===============The profile of %s=================\n\n",prof[dk].name);
printf("\n\tName: %s\n",prof[dk].name);
if(prof[dk].sex)
strcpy(temp,"Female");
else
strcpy(temp,"Male");
printf("\tGender:%s\n",temp);
printf("\tBirthday:%4d %2d %2d\n",prof[dk].birthday.year,prof[dk].birthday.month,prof[dk].birthday.day);
printf("\tWorkday:%4d %2d %2d\n",prof[dk].workday.year,prof[dk].workday.month,prof[dk].workday.day);
switch(prof[dk].rofs){
case 0:
strcpy(temp,"Element school");
break;
case 1:
strcpy(temp,"Middle school");
break;
case 2:
strcpy(temp,"High school");
break;
case 3:
strcpy(temp,"University");
break;
case 4:
strcpy(temp,"Other");
break;
default:
strcpy(temp,"Error");
}
printf("\tThe record of formal schooling:%s\n",temp);
printf("\tPosition:%s\n",prof[dk].position);
printf("\tAddress:%s %s city %s province\n",prof[dk].addr.street,prof[dk].addr.city,prof[dk].addr.province);
printf("\tTelephone number:%s\n",prof[dk].tel);
getch();
}
/*從數(shù)據(jù)庫中搜索一個指定的工人的資料*/
int search(int i,struct WORKER * sp,int mode,char trans[]){
char search_name[20];
int j,n;
/*錯誤處理*/
if(!strcmp(trans,"")){
printf("Please enter the name that you want to search:");
scanf("%s",search_name);
}
else
strcpy(search_name,trans);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -