diff --git a/通信工程1802—李清宇-18408200221.c(1).c b/通信工程1802—李清宇-18408200221.c(1).c new file mode 100644 index 0000000..2d5046a --- /dev/null +++ b/通信工程1802—李清宇-18408200221.c(1).c @@ -0,0 +1,314 @@ +#include +#include +#include +#include +struct infor { + char ID[50]; + char NAME[50]; + float PRICE; + long NUMBER; +}g[1000],m[1000],x; +struct inf { + char id[50]; + char name[50]; + float price; + long number; +}c; + //struct infor g[1000]; + FILE *p; + void menu_s(); + void input(); + void output(); + void check(); + void updata(); + void add(); + void dele(); + void dele2(); + int len(); + int len2(); + int main() + { + system("cls");// + int n; + menu_s(); + scanf("%d",&n); + while(n) + { + system("cls"); + + switch(n) + { + case 1: + input() ;break; + case 2: + output();break; + case 3: + updata();break; + case 4: + check();break; + case 5: + return 0; + } + getch(); + menu_s(); + scanf("%d",&n); + } +} + void menu_s () +{ + printf("----------------------------\n"); + printf("***********˵***********\n"); + printf("*********1:Ʒ*********\n"); + printf("*********2:Ʒ*********\n"); + printf("*********3:¿*********\n"); + printf("*********4:ѯ*********\n"); + printf("*********5:˳ϵͳ*********\n"); + printf("*********ѡ*********\n"); + printf("----------------------------\n"); +} +void input() +{ + int i=0,s; + //struct infor g; + char next[2]="y"; + p=fopen("1.txt","wb+"); + if(p==NULL) + { + printf("ļʧ\n"); + fclose(p); + exit(0); + } + while(strcmp(next,"y")==0||strcmp(next,"Y")==0) + { + printf("\nƷ\n"); + scanf("%s",g[i].ID ); + printf("\nƷ\n"); + scanf("%s",&g[i].NAME ); + printf("\nƷ۸\n"); + scanf("%f",&g[i].PRICE ); + printf("\nƷ\n"); + scanf("%d",&g[i].NUMBER ); + fwrite(&g[i],sizeof(struct infor),1,p);/*ļд*/ + printf("\n루y(Y)/n(N)\n"); + fflush(stdin);//ջ + i++; + //next=getch(); + scanf("%s",next); + } + fclose(p); +} +int len()//ȡǰļ +{ int z=0; + p=fopen("1.txt","r+"); + if(p==NULL) + { + printf("ļʧ\n"); + exit(1); + } + rewind(p);//ļָļͷ + while(!feof(p)) + { + if((fread(&g[z],sizeof(struct infor),1,p))==1); + z++; + } + fclose(p); + return z-1; +} +int len2()//ȡǰļ +{ int z=0; + FILE *fp; + fp=fopen("3.txt","r+"); + if(fp==NULL) + { + printf("ļʧ\n"); + exit(1); + } + rewind(fp);//ļָļͷ + while(!feof(fp)) + { + if((fread(&c,sizeof(struct inf),1,fp))==1); + z++; + } + fclose(fp); + return z; +} + void check() +{ + int i,s=0; + long length; + p=fopen("1.txt","rb+"); + if(p==NULL) + { + printf("ļʧ\n"); + exit(1); + } + printf("\n----------------------------------------------------\nƷб\n----------------------------------------------------\n"); + printf("\t\tƷ\t\t۸\t\t\n"); + rewind(p);//ļָļͷ + /* while(!feof(p)) + { + if((fread(&g[s],sizeof(struct infor),1,p))==1); + s++; + }*/ + s=len(); + rewind(p); + fread(g,sizeof(struct infor),s,p); + for(i=0;i