From dd4b92d0dd86ed3a978f847e37658c77d9379fc8 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 Dec 2023 11:45:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=99=E5=A5=BD=E6=9F=A5=E7=9C=8B=E6=89=80?= =?UTF-8?q?=E6=9C=89=E8=81=94=E7=B3=BB=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- practice_test/main.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/practice_test/main.c b/practice_test/main.c index 6d9606c..3061174 100644 --- a/practice_test/main.c +++ b/practice_test/main.c @@ -1,8 +1,9 @@ #include +#include +#include struct Contact//每个联系人的结构体 { - int age;//年龄 char sex[10];//性别 char name[15];//名字 char email[30];//email @@ -15,7 +16,22 @@ enum Operate//选择的枚举函数 void view_mode(void)//查看所有联系人函数 { - printf("view\n"); + FILE *file=fopen("contact.txt","rb");//打开文件 + int test_file=fgetc(file);//测试是否为空 + if(test_file == EOF) + { + printf("通讯录不存在联系人\n"); + fclose(file);//关闭文件 + return;//结束程序 + } + struct Contact contact;//声明一块结构体临时储存读取到的通讯录 + while(fread (&contact , sizeof(struct Contact) , 1 , file) == 1) + { + printf("姓名:%s",contact.name); + printf(" 性别:%s",contact.sex); + printf(" email:%s\n",contact.email); + } + fclose(file);//关闭文件 } void find_mode(void)//查找联系人函数