求一个C语言编写的通讯录程序?急急急

 我来答
乱中一现
2014-12-08 · 超过17用户采纳过TA的回答
知道答主
回答量:49
采纳率:0%
帮助的人:23.1万
展开全部
#include<stdio.h>
#define LL sizeof(struct Information)
#include<stdlib.h>
struct Information
{
char name[25];
int number;
double Tel_number;
struct Information *next;
};
int n,t;
struct Information *creat()
{
struct Information *head,*p1,*p2;
n=0;
p1=p2=(struct Information *)malloc(LL);
printf("请输入第 %d 个学生通讯信息:\n",n+1);
printf("姓名\t学号\t电话号码\n");
scanf("%s%d%lf",p1->name,&p1->number,&p1->Tel_number);
getchar();
head=NULL;
while(p1->number!=0)
{
n++;
if(n==1)head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct Information *)malloc(LL);
scanf("%s%d%lf",p1->name,&p1->number,&p1->Tel_number);
getchar();
}
p2->next=NULL;
free(p1);
p1=NULL;
return head;
}
void output(struct Information *p3)
{
printf("\n你建立的是多少人的通讯录: n=%d\n ",n);
printf("\n输出存入的通信信息:\n");
printf("\n姓名\t学号\t电话号码\n");
while(p3!=NULL)
{
printf("%s\t%d\t%.0lf\n",p3->name,p3->number,p3->Tel_number);
p3=p3->next;
}
}
void file(struct Information *p8)
{
FILE *fp;
int i;
t=n;
if((fp=fopen("Infor.dat","wb"))==NULL)
{
printf("此文件无法打开!\n");
exit(0);
}
for(i=0;i<t;i++)
{
if(fwrite(&p8->name,LL,1,fp)!=1)
if(fwrite(&p8->number,LL,1,fp)!=1)
if(fwrite(&p8->Tel_number,LL,1,fp)!=1)
p8=p8->next;
else
printf("此文件写入错误\n");
}
fclose(fp);
}
void Insert(struct Information *head,struct Information *node,int num1)
{
struct Information *p;
if(head==NULL)
{
head=node;
node->next=NULL;
n++;
printf("你插入后总共有结点:n=%d\n",n);
}
p=head;
while(p->number!=num1 && p->next!=NULL)
{
p=p->next;
}
if(p->number==num1)
{
node->next=p->next;
p->next=node;
n++;
printf("你插入后总共有结点:n=%d\n",n);
}
else
printf("\nthe num1 is't found!\n");
printf("\n输出插入一个学生的通讯信息后的通讯录:\n");
printf("\n姓名\t学号\t电话号码\n");
p=head;
while(p!=NULL)
{
printf("%s\t%d\t%.0lf\n",p->name,p->number,p->Tel_number);
p=p->next;
}
}
void Delete(struct Information *head,int num2)
{
struct Information *p5,*p6,*p7;
if(head==NULL)
{
printf("\nthis is a null list!\n");
}
p6=head;
while(p6->number!=num2 && p6->next!=NULL)
{
p5=p6;
p6=p6->next;
}
if(p6->number==num2)
{
if(head==p6)
{
head=head->next;
}
else
p5->next=p6->next;
n--;
printf("你 删除 后总共有结点:n=%d\n",n);
}
else
printf("\nthe %d didn't been found!\n");
printf("\n输出 删除 一个学生的通讯信息后的通讯录:\n");
printf("\n姓名\t学号\t电话号码\n");
free(p6);
p6=NULL;
p7=head;
while(p7!=NULL)
{
printf("%s\t%d\t%.0lf\n",p7->name,p7->number,p7->Tel_number);
p7=p7->next;
}
}
int main()
{
struct Information *p0,*p4;
int r,m;
p0=creat();
output(p0);
file(p0);
printf("请输入要 插入 信息:\n");
p4=(struct Information *)malloc(LL);
scanf("%s%d%lf",p4->name,&p4->number,&p4->Tel_number);
getchar();
printf("请输入 插在 那个学号:\n");
scanf("%d",&r);
Insert(p0,p4,r);
printf("请输入 删除 那个学号:\n");
scanf("%d",&m);
Delete(p0,m);
return 0;
}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
背心_心背
2014-12-08 · TA获得超过449个赞
知道小有建树答主
回答量:644
采纳率:100%
帮助的人:525万
展开全部
给报酬帮你写
更多追问追答
追问
多少?
追答
你给多少
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式