From d2d50fdfc8a4edba90252aa4497a2825c3765385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=82=8E=E5=87=89?= <2312524043@qq.com> Date: Wed, 9 Jan 2019 13:24:58 +0800 Subject: [PATCH] fourth commit --- 通讯录管理系统解释.cpp | 252 ++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 通讯录管理系统解释.cpp diff --git a/通讯录管理系统解释.cpp b/通讯录管理系统解释.cpp new file mode 100644 index 0000000..b3c7944 --- /dev/null +++ b/通讯录管理系统解释.cpp @@ -0,0 +1,252 @@ +#include +#include +#include + +#define LEN sizeof(phone) +static int count=0; +FILE *ptr1; +struct txl //ͨṹ巽㴢˵ĸ +{ + char name[10]; + char hometown[10]; + char number1[11]; + char number2[11]; + char e_mail[10]; +}phone[100]; //ͨṹԴ˵ + +void tianjia() +{ + static int i=0; //ʹstatic Ѿ + int j,t; + struct txl *p; + p=phone; + printf("Կʼ\n"); + printf("绰Ųܳ11,!\n"); + printf("䲻ܳ10ַ~~\n"); + ptr1=fopen("sto3.txt","ab+"); + if(ptr1==NULL) + { + ptr1=fopen("sto3.txt","wb+"); + if(ptr1==NULL) + { + printf("Cannot open file"); + exit(0); + } + } + fseek(ptr1,0,SEEK_END);//ʹļָָļĩβʹµ + do + { + printf(":"); + scanf("%s",&p[i].name); printf("\n"); + printf("뼮:"); + scanf("%s",&p[i].hometown); printf("\n"); + printf("绰1:"); + scanf("%s",&p[i].number1);printf("\n"); + printf("绰2:"); + scanf("%s",&p[i].number2); printf("\n"); + printf(":"); + scanf("%s",&p[i].e_mail); printf("\n"); + fwrite(&p[i],LEN,1,ptr1); + printf("һ,Ƿ\n "); + printf("1Ϊ 0Ϊ˳\n"); + fflush(stdin); //ջ棬ݽ뵽ļУΪݴСû512bļʹǿƵĽļ + scanf("%d",&j); + i++;count++; + }while(j!=0&&count!=100); + fclose(ptr1); +} +void chakan()//鿴ҵϵ +{ + FILE *ptr1; + struct txl *p; + p=phone; + char name[10]; + int j=0,i,m=0; + p=phone; + ptr1=fopen("sto3.txt","rb"); + if(ptr1==NULL) + { + printf("ͨѶ¼Ϊ\n"); + return; + } +// rewind(ptr1); + while(!feof(ptr1)) + { + if(fread(&p[m],LEN,1,ptr1)==1)//ļݸֵṹ,˲ſԽݵĶԱҵϵ + m++; + } + fclose(ptr1); + printf("Ҫ鿴˵:"); + scanf("%s",&name); + printf(" ͬ˶:\n"); + printf(" 绰 绰 \n"); + for(i=0;i