From 26933498106632e7329de2fef9110f257eb3c715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=82=8E=E5=87=89?= <2312524043@qq.com> Date: Tue, 8 Jan 2019 08:52:39 +0800 Subject: [PATCH] first commit --- 通讯录3.cpp | 221 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 通讯录3.cpp diff --git a/通讯录3.cpp b/通讯录3.cpp new file mode 100644 index 0000000..da85067 --- /dev/null +++ b/通讯录3.cpp @@ -0,0 +1,221 @@ +#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; + int j,t; + struct txl *p; + p=phone; + printf("¿ÉÒÔ¿ªÊ¼Ìí¼Ó\n"); + ptr1=fopen("sto.txt","ab+"); + if(ptr1==NULL) + { + ptr1=fopen("sto.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); + 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("sto.txt","rb"); +// 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