master
炎凉 7 years ago
parent 2693349810
commit e4caca44fa

15
h1.h

@ -0,0 +1,15 @@
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
#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]; //通过结构体数组可以储存多人的数据

63
h3.c

@ -0,0 +1,63 @@
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<m;i++)
if(strcmp(p[i].name,name)==0)
{
printf("%-10s%-10s%-11s%-11s%-10s\n",p[i].name,p[i].hometown,p[i].number1,p[i].number2,p[i].e_mail);
j=1;
}
if(j==0)
{
printf("\n");
printf("没有此联系人!!\n");
printf("\n");
}
}
void daying()//输出所有的联系人列表
{
struct txl *p;
FILE *ptr1;
int 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("姓名 籍贯 电话 电话 邮箱\n");
for(i=0;i<m;i++)
{
printf("%-10s%-10s%-11s%-11s%-10s\n",p[i].name,p[i].hometown,p[i].number1,p[i].number2,p[i].e_mail);
}
}
Loading…
Cancel
Save