- 论坛徽章:
- 1
|
小妹在这里求求各位高手~~C描述 民航售票处的服务系统
- #include <stdio.h>;
- #include <time.h>;
- #include <stdlib.h>;
- #include <sys/types.h>;
- #include <sys/stat.h>;
- #include <unistd.h>;
- #include <string.h>;
- #include "error.c"
- #define Ssize sizeof(Airline)
- #define FW(a) fwrite(&a,Ssize,1,fp)
- #define FR(a) fread(a,Ssize,1,fp)
- extern char FILENAME[];
- char *all_week[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
- //char *today;
- typedef struct airline
- {
- unsigned int Nflight;
- unsigned int Nplane;
- char Week[10];
- char Date[20];
- char Where[20];
- int Balance;
- }Airline;
- typedef struct list
- {
- Airline *a;
- struct list *next;
- }LIST;
- int init_data()
- {
- FILE *fp;
- Airline a1={1,501,"","","",50}, \
- a2={2,511,"","","",40}, \
- a3={3,520,"","","",20}, \
- a4={4,503,"","","",41};
- strcpy(a1.Week,all_week[2]);
- strcpy(a2.Week,all_week[4]);
- strcpy(a3.Week,all_week[5]);
- strcpy(a4.Week,all_week[6]);
- strcpy(a1.Date,"2005-7-24");
- strcpy(a2.Date,"2005-7-26");
- strcpy(a3.Date,"2005-7-27");
- strcpy(a4.Date,"2005-7-28");
- strcpy(a1.Where,"dalian");
- strcpy(a2.Where,"beijing");
- strcpy(a3.Where,"shanghai");
- strcpy(a4.Where,"shenzhen");
- if((fp=fopen(FILENAME,"w"))<0)
- die("fopen",1);
- FW(a1);
- FW(a2);
- FW(a3);
- FW(a4);
- fclose(fp);
- return 0;
- }
- LIST *read_all_data()
- {
- FILE *fp;
- struct stat st;
- Airline *al;
- LIST *header,*ptr,*tmp;
- int i;
- if((fp=fopen(FILENAME,"r"))<0)
- {
- perror("fopen");
- return NULL;
- }
- if(stat(FILENAME,&st)<0)
- {
- perror("stat");
- return NULL;
- }
- al=(Airline *)malloc(Ssize);
- FR(al);
- header=(LIST *)malloc(sizeof(LIST));
- header->;a=al;
- header->;next=NULL;
- ptr=header;
- for(i=1;i<st.st_size/Ssize;i++)
- {
- al=(Airline *)malloc(Ssize);
- tmp=(LIST *)malloc(sizeof(LIST));
- FR(al);
- tmp->;a=al;
- tmp->;next=NULL;
- ptr->;next=tmp;
- ptr=tmp;
- }
- fclose(fp);
- return header;
- }
复制代码
这是data.c 文件. |
|