C语言编写通讯录项目有谁会啊
发布网友
发布时间:2022-04-26 08:48
我来回答
共5个回答
热心网友
时间:2022-06-26 02:12
#include <string.h>
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>//包含system函数头文件
#define LEN sizeof(struct student)
struct student
{
char num[20];//ID号码
char name[100];//用户姓名
char phone[20];//电话号码
char home[100];//通讯地址
char birthday[20];//出生日期
struct student *next;
};
void face(void)//功能选择面板
{
printf("********************************************************************");
printf("\t\t\t\t☆★☆★☆★ ~_~ ~_~ ~_~ ☆★☆★☆★\n");
printf("\n\t\t\t☆★欢迎使用阿冬子通讯录☆★");
printf("\n\n\t☆★选择你需要操作的功能:☆★(现无记录,建议先填加记录)★☆\n");
printf("\n");
printf("\t\t\t1.【增加通讯录信息〗\n");
printf("\t\t\t2.〖显示通讯录中所有记录】\n");
printf("\t\t\t3.【删除需要删除的信息〗\n");
printf("\t\t\t4.〖以名字查询所需的信息】\n");
printf("\t\t\t5.【保存通讯录中的所有记录到指定文件中〗\n");
printf("\t\t\t6.〖退出不保存!!】\n");
printf("\n");
printf("\t☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★");
printf("\n\n********************************************************************\n\n");
}
void print(struct student *head)
{
struct student *p;
p=head;
system("CLS");//调用DOS命令CLS能够清屏
printf("*************************************************************\n");
printf("==================== → 用户信息记录表 ← ===================\n");
printf("*************************************************************\n");
if(head!=NULL)
do
{
printf("联系人ID号码:%s\n",p->num);
printf("联系人姓名:%s\n",p->name);
printf("联系人电话号码:%s\n",p->phone);
printf("学生地址:%s\n",p->home);
printf("联系人出生日期:%s\n",p->birthday);
printf("********************************************************\n");
p=p->next;
}while(p!=NULL);
else
{
printf("对不起!!没有任何联系人记录!!\n\n");
printf("=============================================================\n");
}
}
//增添电子通讯录中的内容,即创建连表过程
struct student *append(struct student *head)
{
struct student *p0=NULL,*p1,*p2;//p0为要插入的新节点
p1=head;
p2=head;
system("CLS");
printf("\n\n***********************************************************\n");
printf("\t\t你能在此目录下创建并添加联系人信息");
printf("\n***********************************************************\n");
p0=(struct student *)malloc(LEN);
printf("请输入联系人ID号码:");
gets(p0->num);
printf("请输入联系人姓名:");
gets(p0->name);
printf("请输入联系人电话号码:");
gets(p0->phone);
printf("请输入联系人地址:");
gets(p0->home);
printf("请输入联系人出生日期:");
gets(p0->birthday);
//对插入的节点排序,按姓名的拼音顺序
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{
while((strcmp(p0->name,p1->name)>0)&&(p1->next!=NULL))
{p2=p1;p1=p1->next;}
if((strcmp(p0->name,p1->name))<=0)
{
if(head==p1)
head=p0;
else
p2->next=p0;
p0->next=p1;
}
else
{p1->next=p0;p0->next=NULL;}
printf("恭喜你!!成功添加了联系人信息!!");
printf("\n************************************************************\n");
printf("\n\n");
}
return(head);
}
//电子通讯录的维护(删除),通过输入联系人ID号码删除联系人数据
struct student *del(struct student *head)
{
struct student *p1,*p2;
char num[12];
system("CLS");
printf("\n\n************************************************************\n");
printf("================= → 用户信息记录删除功能 ← ===============\n");
printf("************************************************************\n");
printf("输入要删除的联系人ID号码:");
gets(num);
p1=head;
if (head==NULL)
{
printf("很抱歉!!没有任何联系人纪录!!\n");
printf("\n*******************************************************\n");
return(head);
}
while(p1!=NULL)
{
if(strcmp(p1->num,num)==0)
{
if(p1==head)
head=p1->next;
else p2->next=p1->next;
free(p1);
printf("删除记录成功!!\n");
return(head);
}
p2=p1;
p1=p1->next;
}
printf("对不起!!没有要删除的联系人纪录!!\n");
return(head);
}
//电子通讯录的查找,关键字为用户姓名;
void search(struct student *head)
{
struct student *p1,*p2;
char name[20];
p1=head;
p2=p1;
system("CLS");
printf("\n**************************************************************\n");
printf("================ → 用户信息记录查询功能 ← ==================\n");
printf("**************************************************************\n");
printf("输入要查找联系人的姓名:");
gets(name);
while(p1!=NULL)
{
if(strcmp(p1->name,name)==0)
{
printf("联系人ID号码:");
puts(p1->num);
printf("联系人姓名:");
puts(p1->name);
printf("联系人电话号码:");
puts(p1->phone);
printf("联系人地址:");
puts(p1->home);
printf("联系人出生日期:");
puts(p1->birthday);
printf("\n=============================================================\n");
break;
}
p2=p1;
p1=p1->next;
}
if(p1==NULL)
printf("对不起!!没有该联系人的纪录!!\n");
}
//电子通讯录的记录存盘操作,使用文件指针;
void save(struct student *head)
{
FILE *fp,*fp1;
struct student *p;
p=head;
fp=fopen("record.txt","w");
fp1=fopen("record1.txt","w");
fprintf(fp1,"=============== → 用户信息记录表 ← =================\n");
while(p!=NULL)
{
//首先把数据保存在record.txt中,这是提供给load函数用的数据
//fprintf(fp," %s %s %s %s %s %s",p->num,p->name,p->phone,p->email,p->home,p->birthday);
//然后把数据保存在record1.txt中,这是能提供直接查询看的,有比较友好的画面
fprintf(fp1,"====================================================\n");
fprintf(fp1,"联系人ID号码:%s\n",p->num);
fprintf(fp1,"联系人姓名:%s\n",p->name);
fprintf(fp1,"联系人电话:%s\n",p->phone);
fprintf(fp1,"联系人家庭地址:%s\n",p->home);
fprintf(fp1,"联系人出生日期:%s\n",p->birthday);
p=p->next;
}
fprintf(fp1,"*************************************************************\n");
fclose(fp1);
fclose(fp);
printf("\n\n恭喜你!!成功储存,你能在record1.txt找到相应纪录\n");
printf("**************************************************************\n");
printf("PRESS ANY KEY TO EXIT.\n\n");
getchar();
exit(1);
}
//电子通讯录的记录读盘操作,使用文件指针;
struct student *load(void)
{
FILE *fp;
struct student *head=NULL,*p1=NULL,*p2=NULL;
char c;
int i;
fp=fopen("record.txt","r");
for(i=1;(c=fgetc(fp))!=-1;i++)
{
p1=(struct student *)malloc(LEN);
//fscanf(fp,"%s %s %s %s %s %s",p1->num,p1->name,p1->phone,p1->email,p1->home,p1->birthday);
if(i==1)
{head=p1;p2=p1;}
else
{p2->next=p1;p2=p1;}
}
if(p1==NULL)
{fclose(fp);return(head);}
p2->next=NULL;
fclose(fp);
return(head);
}
main()
{
FILE *fp1,*fp2;
int c;//功能选择需要的号码
system("cls");
system("color 2f");
system("cls");
struct student *head=NULL;
if ((fp1=fopen("record.txt","r"))==NULL)
{
fp2=fopen("record.txt","w");//如果不存在record.txt就创建一个
fclose(fp2);
}
head=load();
while(1)
{
face();
printf("选择你需要操作的功能号码:");
scanf("%d",&c);
getchar();
switch(c)
{
case 1:head=append(head);break;
case 2:print(head);break;
case 3:head=del(head);break;
case 4:search(head);break;
case 5:save(head);break;
case 6:exit(0);break;
default :printf("Enter error!!\n");
}
//printf("*****************\n");
printf("◇◆请按ENTER返回功能操作菜单◇◆\n");
//printf("*****************\n");
getchar();
system("CLS");
}
}
热心网友
时间:2022-06-26 02:12
我帮你编了一个,学习学习:
#include"stdio.h"
#include"stdlib.h"
struct student
{
int no; /*学号*/
char name[10]; /*姓名*/
char acdamic[10]; /*院系*/
char major[10]; /*专业*/
char province[10]; /*籍贯*/
char address[40]; /*家庭地址*/
long phone; /*联系电话*/
struct student *next;
};
struct student ss[30]; /*定义这个通讯录的人数为30,但可以根据需要改动*/
struct student *input(int n) /*输入函数*/
{
struct student *h=NULL,*p,*q;
extern struct student ss[30];
int i;
for(i=0;i<n;i++)
{
printf("请依次输入第%d个学生的学号,姓名,系别,专业,籍贯,家庭住址和联系电话:\n",i+1);
p=(struct student *)malloc(sizeof(struct student));
scanf("%d,%s,%s,%s,%s,%s,%ld",&ss[i].no,ss[i].name,ss[i].acdamic,ss[i].major,ss[i].province,ss[i].address,&ss[i].phone);
if(i==1)h=p;
else q->next=p;
q=p;
}
q->next=NULL;
return h;
}
void print(struct student *h) /*输出函数*/
{
struct student *p=h;
extern struct student ss[30];
int i;
while(p->next)
{
printf("学生信息:\n%d %s %s %s %s %s %ld\n",ss[i].no,ss[i].name,ss[i].acdamic,ss[i].major,ss[i].province,ss[i].address,ss[i].phone);
p=p->next;
i++;
}
printf("学生信息:\n%d %s %s %s %s %s %ld\n",ss[i].no,ss[i].name,ss[i].acdamic,ss[i].major,ss[i].province,ss[i].address,ss[i].phone);
}
struct student *insert(struct student *h,int n) /*增加学生信息*/
{
struct student *p,*r;
int i;
for(i=0;i<n;i++)
{
r=(struct student *)malloc(sizeof(struct student));
printf("请输入第%d个你要插入的学生的信息:\n",i+1);
scanf("%d %s %s %s %s %s %ld",&r->no,r->name,r->acdamic,r->major,r->province,r->address,&r->phone);
p=h;
h=r;
r->next=p;
}
return h;
}
struct student *del(struct student *h,int n) /*按学号进行删除*/
{
struct student *p,*q;
if(h=NULL)printf("empty list!\n");
else
{
p=h;
while(p->no!=n&&p->next)
{q=p;p=p->next;}
if(p->no==n)
{
if(h==p)h=p->next;
else q->next=p->next;
}
else printf("%d is not found!\n");
}
return h;
}
void find(struct student *h,int n)
{
struct student *p,*q;
if(h==NULL)printf("empty list!\n");
else
{
p=h;
while(p->no!=n&&p)
{q=p;p=p->next;}
if(p->no==n)
printf("学生信息:\n%d %s %s %s %s %s %ld\n",p->no,p->name,p->acdamic,p->major,p->province,p->address,p->phone);
else printf("the student is not in the list!\n");
}
}
main()
{
struct student *input(int n);
void print(struct student *h);
struct student *insert(struct student *h,int n);
struct student *del(struct student *h,int n);
void find(struct student *h,int n);
int n,no1,no2,no3,i;
struct student *h,*p,*q;
printf("请输入你要创建的学生通讯录的学生个数(n<30):");
scanf("%d",&n);
h=input(n);
print(h);
printf("请输入你要增加的学生信息的个数:");
scanf("%d",&no1);
for(i=0;i<no1;i++)
p=insert(h,no1);
print(p);
printf("请输入你要删除的学生的学号:\n");
scanf("%d",&no2);
q=del(p,no2);
print(q);
printf("请输入你要查找的学生学号:\n");
scanf("%d",&no3);
find(q,no3);
}
热心网友
时间:2022-06-26 02:13
我帮你编了一个,你自己拿去用用吧.
花了我两个小时哦.
#include"stdio.h"
#include"stdlib.h"
struct student
{
int no; /*学号*/
char name[10]; /*姓名*/
char acdamic[10]; /*院系*/
char major[10]; /*专业*/
char province[10]; /*籍贯*/
char address[40]; /*家庭地址*/
long phone; /*联系电话*/
struct student *next;
};
struct student ss[30]; /*定义这个通讯录的人数为30,但可以根据需要改动*/
struct student *input(int n) /*输入函数*/
{
struct student *h=NULL,*p,*q;
extern struct student ss[30];
int i;
for(i=0;i<n;i++)
{
printf("请依次输入第%d个学生的学号,姓名,系别,专业,籍贯,家庭住址和联系电话:\n",i+1);
p=(struct student *)malloc(sizeof(struct student));
scanf("%d,%s,%s,%s,%s,%s,%ld",&ss[i].no,ss[i].name,ss[i].acdamic,ss[i].major,ss[i].province,ss[i].address,&ss[i].phone);
if(i==1)h=p;
else q->next=p;
q=p;
}
q->next=NULL;
return h;
}
void print(struct student *h) /*输出函数*/
{
struct student *p=h;
extern struct student ss[30];
int i;
while(p->next)
{
printf("学生信息:\n%d %s %s %s %s %s %ld\n",ss[i].no,ss[i].name,ss[i].acdamic,ss[i].major,ss[i].province,ss[i].address,ss[i].phone);
p=p->next;
i++;
}
printf("学生信息:\n%d %s %s %s %s %s %ld\n",ss[i].no,ss[i].name,ss[i].acdamic,ss[i].major,ss[i].province,ss[i].address,ss[i].phone);
}
struct student *insert(struct student *h,int n) /*增加学生信息*/
{
struct student *p,*r;
int i;
for(i=0;i<n;i++)
{
r=(struct student *)malloc(sizeof(struct student));
printf("请输入第%d个你要插入的学生的信息:\n",i+1);
scanf("%d %s %s %s %s %s %ld",&r->no,r->name,r->acdamic,r->major,r->province,r->address,&r->phone);
p=h;
h=r;
r->next=p;
}
return h;
}
struct student *del(struct student *h,int n) /*按学号进行删除*/
{
struct student *p,*q;
if(h=NULL)printf("empty list!\n");
else
{
p=h;
while(p->no!=n&&p->next)
{q=p;p=p->next;}
if(p->no==n)
{
if(h==p)h=p->next;
else q->next=p->next;
}
else printf("%d is not found!\n");
}
return h;
}
void find(struct student *h,int n)
{
struct student *p,*q;
if(h==NULL)printf("empty list!\n");
else
{
p=h;
while(p->no!=n&&p)
{q=p;p=p->next;}
if(p->no==n)
printf("学生信息:\n%d %s %s %s %s %s %ld\n",p->no,p->name,p->acdamic,p->major,p->province,p->address,p->phone);
else printf("the student is not in the list!\n");
}
}
main()
{
struct student *input(int n);
void print(struct student *h);
struct student *insert(struct student *h,int n);
struct student *del(struct student *h,int n);
void find(struct student *h,int n);
int n,no1,no2,no3,i;
struct student *h,*p,*q;
printf("请输入你要创建的学生通讯录的学生个数(n<30):");
scanf("%d",&n);
h=input(n);
print(h);
printf("请输入你要增加的学生信息的个数:");
scanf("%d",&no1);
for(i=0;i<no1;i++)
p=insert(h,no1);
print(p);
printf("请输入你要删除的学生的学号:\n");
scanf("%d",&no2);
q=del(p,no2);
print(q);
printf("请输入你要查找的学生学号:\n");
scanf("%d",&no3);
find(q,no3);
}
热心网友
时间:2022-06-26 02:13
主要功能:主菜单的输入和输出
添加
删除
查找
代码如下;
#include <stdio.h>
#include <stdlib.h> /*与malloc.h差不多*/
#include <string.h>
#include <iostream>
using namespace std;
#define maxlen 15
struct persons
{int num; /*定义结构体数组用于缓存数据*/
char name[20];
char e_addr[20];
char tel_no[15];
char sim_no;
char arch;
}persons[maxlen];
typedef struct lnode
{ /*通讯录结构中结点的定义*/
int num;
char name[20];
char e_addr[20];
char tel_no[15];
char sim_no;
char arch;
struct lnode *next;
}listnode,*linklist;
linklist head=NULL,r=NULL; /*定义头指针和尾指针*/
listnode *s,*p0,*p1,*p2,*p3,*p4,*p5,*p6,*p7,*p8,*p9;
int i;
char name1[10],ch;
char tel_no1[15];
char arch1;
char sim_no1;
char e_addr1[20];
char s1[20];
FILE *fp; /*定义文件指针*/
void creat() /*将文件的信息读入结构体数组在转存入链表中*/
{ int j;
long k;
fp=fopen("数据文件.txt","r t"); /*打开文件*/
if(fp!=NULL)
{for(i=0;i<=maxlen;i++ )
{ j=fgetc(fp);
if(j==EOF)
return;
k=i;
fseek(fp,k*sizeof(struct persons),0); /*读取一个人的信息*/
fread(&persons[i],sizeof(struct persons),1,fp);
s=(linklist)malloc(sizeof(listnode)); /*装存入链表中*/
s->num=persons[i].num;
strcpy(s->name,persons[i].name);
strcpy(s->e_addr,persons[i].e_addr);
strcpy(s->tel_no,persons[i].tel_no);
s->sim_no=persons[i].sim_no;
s->arch=persons[i].arch;
if(head==NULL) /*用尾插法将其插入链表中*/
else
{r->next=s;
r=s;r->next=NULL;
}
}fclose(fp);
}
else
{ fp=fopen("数据文件.txt","w"); /*不能打开另开辟一个文件*/
i=1;
}
}
void Show()
void Delete()
void Input() /*向.通讯录中输入一个人的信息*/
{ s=(linklist)malloc(sizeof(listnode));
printf("\n\n\t请输入该用户的信息:");
printf("姓名:");
scanf("%s",&s->name);
printf("电话号码:");
scanf("%s",&s->tel_no);
printf("单键拨号:");
scanf("%s",&s->sim_no);
printf("E-mail地址:");
scanf("%s",&s->e_addr);
printf("类别:");
scanf("%s",&s->arch);
if(head==NULL)printf("\n\n");
else
{p8=head;
while(p8!=NULL&&strcmp(s->name,p8->name)!=0&&strcmp(s->tel_no,p8->tel_no)!=0)
p8=p8->next;
if(p8!=NULL)
{printf("您添加的用户已存在!");
free(s);}}
if(head==NULL)
{
s->next = 0;
head=s;
r = s;
}
else
{
s->next = 0;
r->next = s;
r = s;
}
}
void Alter()
int main()
{
system("color a");
creat();
do
{
printf("\n\n\t\t请选择操作:");
printf("\n\t\t1.显示通讯录");
printf("\n\t\t2.删除通讯录");
printf("\n\t\t3.添加通讯录");
printf("\n\t\t4.编辑通讯录");
printf("\n\n\n");
printf("\t请选择:");
cin>>ch;
switch(ch)
{ case '1': Show(); /*用单条件多选择语句实现调用与循环*/
break;
case '2': Delete();
break;
case '3': Input();
break;
case '4': Alter();
break;
fclose(fp);
exit(0);
break;
default:
printf("\n\t The num should 1-6!!! \n");
break;
}
}
while(1);
}
热心网友
时间:2022-06-26 02:14
世上好人多啊