资源简介

功能:添加,删除,查找,全部输出。 添加时自动保存到文件, 查找、全部输出时从文件中读取; 复制粘贴即可运行!绝对好用

资源截图

代码片段和文件信息

#include
#include
#include
struct inf
{
char num[20];
char name[12];
char tel[20];
struct inf *next;
};
int count()
{
FILE *fp;
int nx;
    fp=fopen(“通讯录.txt““r“);
fseek(fp 0L SEEK_END);
    n = ftell(fp);//n是文件的字节总数
fseek(fp 0L SEEK_SET);
x=n/56;
return x;
}
int select()/*******************************选择***************************************/
{
int num;
printf(“\n请选择\n“);
scanf(“%d“&num);
printf(“\n“);
return num;
}
struct inf *create()/*******************************创建***************************************/
{
struct inf *head*temp*tail;
temp=(struct inf*)malloc(sizeof(struct inf));
temp->next=0;
head=tail=temp;
return head;
}
void add(struct inf *headstruct inf *p) /*******************************添加***************************************/
{
struct inf *p1*p2;
p1=head;
p2=p1->next;
while(p2!=0&&p2->numnum)
{
p1=p2;
p2=p2->next ;
}
p1->next=p;
p->next=p2;
}
struct inf *find(struct inf *head)/*******************************查找***************************************/
{
struct inf *p1;
FILE *fp;
char n[12];
int ix;
fp=fopen(“通讯录.txt““r“);
x=count();
printf(“输入姓名:\n“);
scanf(“%s“&n);
for(i=0;i {
p1=(struct inf*)malloc(sizeof(struct inf));
fseek(fpi*sizeof(struct inf)0);
fread(p1sizeof(struct inf)1fp);
if(strcmp(p1->namen)==0)
{
return p1;
}
}
if(i==x)
{
return 0;
}
}
void print(struct inf *p)/*******************************单个输出***************************************/
{
printf(“%s:\t姓名:%s\t电话:%s\n\n“p->nump->name p->tel);
}
void printall(struct inf *head)/*******************************全部输出***************************************/
{
struct inf *p;
p=head->next;
while(p!=NULL)
{
printf(“%s:\t姓名:%s\t电话:%s\n“p->nump->namep->tel);
p=p->next;
}
}
void del(struct inf *head)/*******************************删除***************************************/
{
struct inf *p1*p;
FILE *fp;
char n[12]d;
int ix;
fp=fopen(“通讯录.txt““r“);
x=count();
printf(“输入姓名:\n“);
scanf(“%s“&n);
for(i=0;i {
p1=(struct inf*)malloc(sizeof(struct inf));
fseek(fpi*sizeof(struct inf)0);
fread(p1sizeof(struct inf)1fp);
if(strcmp(p1->namen)==0)
{
break;
}
}
if(i==x)
{
printf(“未找到!\n\n“);
}
else
{
if(i!=-1)
{
printf(“真的要删除吗?(Y/N)\n“);
getchar();
scanf(“%c“&d);
if(d==‘Y‘||d==‘y‘)
{
p=(struct inf*)malloc((x-1)*sizeof(struct inf));
fseek(fp0L0);
fread(psizeof(struct inf)ifp);
fseek(fp(i+1)*sizeof(struct inf)0);
fread(psizeof(struct inf)x-i-1

评论

共有 条评论