⑴ 用C语言编写手机通讯录程序
以前写了一个简单的:
#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);
}
⑵ 跪求注释C语言通讯录代码 谢谢 QAQ代码太长 急需 详细一点 感谢
发我帮你注释下
⑶ 用C语言编写通讯录,求程序代码
分析:
跟据楼主的意思!我们可以得出,这个程序只要求我们写查询通迅录的内容
而通迅录的内容,可以通过初始化得出!
简而言之:写一个查询函数
呵呵···把问题相通了,我们就开始写算法吧let's go!!!
----------------------------------------------------------------
算法:
1.获得用户的输入 (就是要查询的对象的名字)
2.查询 (在这我用穷举通迅录的方式查询了,^_^&&^_^)
3.输出查询结果
算法就这样被我们征服了!!!呵呵~~好有成就感哇!!
但我们现在还不能开始编码,我得们先想好怎么编,要做到胸有成竹!!!
那我现在来想一下该怎么编码吧!let's go!!!
----------------------------------------------------------------
要保存通迅的信息,那么我们得用一个结构体吧:
struct friends
{
char name[20]; /* 名字不能写得太长哦 */
char province[20]; /* 省份 */
char city[20]; /* 所在城市 */
char nation[20]; /* 民族 */
char sex[2]; /* 性别 M/F */
int age; /* 年龄 */
};
要获得用户输入,要用个 char search_name[20];
查询结果反回一个数,记录对象在通迅录中的位置:int index;
查询中有用要循环,用一个记数器: int i;
----------------------------------------------------------------
OK,该用的变量我们都想好了!算法我们也想好了。还等什么呢,开始编码吧
呵呵~~是不是等这个时候都等得急了~~~~~
-------------------------------------------------------------------
*******************************************************************
******* 程序实现:
*******************************************************************
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* 定义保存通迅录的信息 */
struct friends
{
char name[20]; /* 名字 */
char province[20]; /* 省份 */
char city[20]; /* 所在城市 */
char nation[20]; /* 民族 */
char sex[2]; /* 性别 M/F */
int age; /* 年龄 */
};
void getname (char search_name[]);
int search (struct friends friend_list[], char search_name[]);
void print_result(struct friends friend_list[], int index);
int main (void)
{
int index;
char search_name[20];
struct friends friend_list[4] = {
{"lihan", "liaoning", "huluo","han","M",19},
{"zhuqiang", "jiangsu", "changzhu", "han","M",19},
{"wangjiangang", "liaoning", "anshan","han","M",20},
{"zhanghongwei", "shandong", "zhucheng", "han","M",21},
};
(void) getname (search_name); /* 获得用户输入 */
index = search (friend_list, search_name); /* 查询 */
(void) print_result (friend_list,index); /* 打印结果 */
return 0;
}
/****************************************
*** 函数名:getname
*** 功能:获得用户要查询的对象的名字
****************************************/
void getname (char search_name[])
{
printf ("Pleace enter the name of your friends you want to search>>");
scanf ("%s", search_name);
}
/****************************************
*** 函数名:search
*** 功能:查询对象
****************************************/
int search (struct friends friend_list[], char search_name[])
{
int i;
/* 穷举通迅录 */
for (i = 0; i < 4; ++i)
{
if (strcmp(friend_list[i].name, search_name) == 0)
{
return (i);
}
}
if (i == 4)
{
printf ("I am sorry! there is nobody by the name you enter!\n");
fflush(stdin);
getchar();
exit (0);
}
}
/****************************************
*** 函数名:print_result
*** 功能:打印结果
****************************************/
void print_result(struct friends friend_list[], int index)
{
printf ("the imformation of %s:\n", friend_list[index].name);
printf ("------------------------------------------------\n");
printf (" NAME: %-s\n", friend_list[index].name);
printf ("PROVINCE: %-s\n", friend_list[index].province);
printf (" CITY: %-s\n", friend_list[index].city);
printf (" NATION: %-s\n", friend_list[index].nation);
printf (" SEX: %-s\n", friend_list[index].sex);
printf (" AGE: %-d\n", friend_list[index].age);
printf ("-------------------------------------------------\n");
fflush(stdin);
getchar();
}
*****************************************************************************
*****************************************************************************
呵呵~~一口气把它写出来了!!!前期写算法是很重要的!!
现在还没结束!!我们要先来测试一下!!
--------------------------------------
Pleace enter the name of your friends you want to search>>lihan
the imformation of lihan:
------------------------------------------------
NAME: lihan
PROVINCE: liaoning
CITY: huluo
NATION: han
SEX: M
AGE: 19
-------------------------------------------------
--------------------------------------
Pleace enter the name of your friends you want to search>>lbmzwyy
I am sorry! there is nobody by the name you enter!
说明成功了~~~呵呵~~太高兴了~~
--------------------------------------
请记注一点:克制编码的诱惑
无论多么小的问题都要先分析好问题,想好算法,才能开始编码!!!我相信这样做一定对你有好处的!
⑷ C语言 通讯录源代码 无链表 无指针
#include<stdio.h> /*引用库函数*/
#include<stdlib.h>
#include<ctype.h>
#include<string.h>typedef struct /*定义结构体数组*/
{
char num[10]; /*学号*/
char name[20]; /*姓名*/
char sushe[20];/*宿舍*/
char tel[20];/*电话*/
char qq[20];/*QQ号码*/
char email[20];/*电子邮箱*/
}Student;
Student stu[80]; /*结构体数组变量*/ int menu_select() /*菜单函数*/
{
char c;
do{
system("cls"); /*运行前清屏*/
printf("\t\t |☆☆☆☆☆☆通讯录信息管理系统☆☆☆☆☆\n"); /*菜单选择*/
printf("\t\t |****************************************|\n");
printf("\t\t |******** 1. 输入学生信息 ***************|\n");
printf("\t\t |******** 2. 查看完整信息 ***************|\n");
printf("\t\t |******** 3. 按学号进行排列 *************|\n");
printf("\t\t |******** 4. 修改通讯录信息 *************|\n");
printf("\t\t |******** 5. 删除通讯录信息 *************|\n");
printf("\t\t |******** 6. 按姓名检索信息 *************|\n");
printf("\t\t |******** 7. 读取文件 *******************|\n");
printf("\t\t |******** 8. 保存文件 *******************|\n");
printf("\t\t |******** 0. 退出系统 *******************|\n");
printf("\t\t |****************************************|\n");
printf("\t\t |***制作人:QIANG *****|\n");
printf("\t\t |****************************************|\n");
printf("\t\t (*^__^*) 您好,请选择(*^__^*)→→→(0-8):");
c=getchar(); /*读入选择*/
}while(c<'0'||c>'9');
return(c-'0'); /*返回选择*/
}
int Input(Student stud[],int n) /*输入若干条记录*/
{
int i=0,p=0;
char sign,f,x[10]; /*x[10]为清除多余的数据所用*/
while(sign!='n'&&sign!='N') /*判断*/
{
printf("\t\t\t请输入学号:"); /*交互输入*/
scanf("\t\t\t%s",stud[n+i].num);
for(p=0;p=n;p++)
{
if(strcmp(stud[p].num,stud[n+i].num)==0)
{
printf("\t\t\t学号已经存在!\n");
system("pause");
return(n);
}
}
printf("\t\t\t请输入姓名:");
scanf("\t\t\t%s",stud[n+i].name);
printf("\t\t\t请输入住址:");
scanf("\t\t\t%s",stud[n+i].sushe);
printf("\t\t\t请输入电话号码:");
scanf("\t\t\t%s",stud[n+i].tel);
printf("\t\t\t请输入QQ:");
scanf("\t\t\t%s",stud[n+i].qq);
printf("\t\t\t请输入电子邮箱:");
scanf("\t\t\t%s",&stud[n+i].email);
gets(x); /*清除多余的输入*/
printf("\t\t\tany more records?(Y/N)");
scanf("\t\t\t%c",&sign); /*输入判断*/
i++;
}
return(n+i);
} void Display(Student stud[],int n) /*显示所有记录*/
{
int i;
printf("--------------------------------------------------------------------------------\n"); /*格式头*/
printf("学号 名字 住址 电话号码 QQ号码 电子邮箱\n");
printf("--------------------------------------------------------------------------------\n");
for(i=1;i<n+1;i++) /*循环输入*/
{
printf("%-16s%-15s%-15s%-15s%-15s%-15s\n",stud[i-1].num,stud[i-1].name,stud[i-1].sushe,stud[i-1].tel,stud[i-1].qq,stud[i-
1].email);
if(i>1&&i%10==0) /*每十个暂停*/
{printf("--------------------------------------------------------------------------------\n"); /*格式*/ <br> printf("\t\t\t"); <br> system("pause"); <br> printf("--------------------------------------------------------------------------------\n"); <br> }
}
printf("\t\t\t");
system("pause");
} void Sort_by_num(Student stud[],int n) /*按学号排序*/
{ int i,j;
char t[10];
for(i=0;i<n-1;i++) /*冒泡法排序*/
for(j=0;j<n-1-i;j++)
if(strcmp(stud[j].num,stud[j+1].num)>0)
{
strcpy(t,stud[j+1].num);
strcpy(stud[j+1].num,stud[j].num);
strcpy(stud[j].num,t);
strcpy(t,stud[j+1].name);
strcpy(stud[j+1].name,stud[j].name);
strcpy(stud[j].name,t);
strcpy(t,stud[j+1].sushe);
strcpy(stud[j+1].sushe,stud[j].sushe);
strcpy(stud[j].sushe,t);
strcpy(t,stud[j+1].tel);
strcpy(stud[j+1].tel,stud[j].tel);
strcpy(stud[j].tel,t);
strcpy(t,stud[j+1].qq);
strcpy(stud[j+1].qq,stud[j].qq);
strcpy(stud[j].qq,t);
strcpy(t,stud[j+1].email);
strcpy(stud[j+1].email,stud[j].email);
strcpy(stud[j].email,t);
}
} void Query_a_record(Student stud[],int n) /*查找并显示一个记录*/
{
char s[20];
int i=0;
printf("\t\t\t请输入要查找的人的名字:"); /*交互式输入*/
scanf("\t\t\t%s",s);
while(strcmp(stud[i].name,s)!=0&&i<n) i++; /*查找判断*/
if(i==n)
{
printf("\t\t\t对不起,查无此人!\n"); /*输入失败信息*/
return;
}
printf("\t\t\t学号:%s\n",stud[i].num); /*输出该学生信息*/
printf("\t\t\t住址:%s\n",stud[i].sushe);
printf("\t\t\t电话号码:%s\n",stud[i].tel);
printf("\t\t\tQQ号码:%s\n",stud[i].qq);
printf("\t\t\t电子邮箱:%s\n",stud[i].email);
}
int Delete_a_record(Student stud[],int n) /*按姓名查找,删除一条记录*/
{
char s[20];
int i=0,j;
printf("\t\t\t请输入要删除的人的名字:"); /*交互式问寻*/
scanf("%s",s);
while(strcmp(stud[i].name,s)!=0&&i<n) i++; /*查找判断*/
if(i==n)
{
printf("\t\t\t对不起,查无此人!\n"); /*返回失败信息*/
return(n);
}
for(j=i;j<n-1;j++) /*删除操作*/
{
strcpy(stud[j].num,stud[j+1].num);
strcpy(stud[j].sushe,stud[j+1].sushe);
strcpy(stud[j].tel,stud[j+1].tel);
strcpy(stud[j].qq,stud[j+1].qq);
strcpy(stud[j].name,stud[j+1].name);
strcpy(stud[j].email,stud[j+1].email);
}
printf("\t\t\t删除成功!\n"); /*返回成功信息*/
return(n-1);
}
int AddfromText(Student stud[],int n) /*从文件中读入数据*/
{
int i=0,num;
FILE *fp; /*定义文件指针*/
char filename[20]; /*定义文件名*/
printf("\t\t\t请您输入要读取的文件名:");
scanf("\t\t\t%s",filename); /*输入文件名*/
if((fp=fopen(filename,"rb"))==NULL) /*打开文件*/
{
printf("\t\t\t打开文件失败!\n"); /*打开失败信息*/
printf("\t\t\t");
system("pause");
return(n);
}
fscanf(fp,"%d",&num); /*读入总记录量*/
while(i<num) /*循环读入数据*/
{
fscanf(fp,"%s%s%s%s%s%s",stud[n+i].num,stud[n+i].name,stud[n+i].sushe,stud[n+i].tel,stud[n+i].qq,stud[n+i].email);
i++;
}
n+=num;
fclose(fp); /*关闭文件*/
printf("\t\t\t读取成功!\n");
printf("\t\t\t");
system("pause");
return(n);
} void WritetoText(Student stud[],int n) /*将所有记录写入文件*/
{
int i=0;
FILE *fp; /*定义文件指针*/
char filename[20]; /*定义文件名*/
printf("\t\t\t保存文件\n"); /*输入文件名*/
printf("\t\t\t请您为文件取个名字:");
scanf("\t\t\t%s",filename);
if((fp=fopen(filename,"w"))==NULL) /*打开文件*/
{
printf("\t\t\t成功!\n");
system("pause");
return;
}
fprintf(fp,"%d\n",n); /*循环写入数据*/
while(i<n)
{
fprintf(fp,"%s %s %s %s %s %s \n",stud[i].num,stud[i].name,stud[i].sushe,stud[i].tel,stud[i].qq,stud[i].email);
i++;
}
fclose(fp); /*关闭文件*/
printf("成功!\n"); /*返回成功信息*/
} int Modify_a_record(Student stud[],int n) /*按姓名查找,修改一条记录*/
{
char s[20];
char newname[20];
char newnum[20];
char newsushe[20];
char newtel[20];
char newqq[20];
char newemail[20];
int i=0;
printf("\t\t\t输入要修改人的名字:"); /*交互式问寻*/
scanf("%s",s);
while(strcmp(stud[i].name,s)!=0&&i<n) i++; /*查找判断*/
if(i==n)
{
printf("\t\t\t找不到这个信息!\n"); /*返回失败信息*/
return(n+1);
}
printf("请输入新姓名:");
scanf("%s",newname);
strncpy(stud[i].name,newname,sizeof(stud[i].name));
stud[i].name[sizeof(stud[i].name)-1]='\0'; printf("请输入新学号:");
scanf("%s",newnum);
strncpy(stud[i].num,newnum,sizeof(stud[i].num));
stud[i].num[sizeof(stud[i].num)-1]='\0'; printf("请输入新地址:");
scanf("%s",newsushe);
strncpy(stud[i].sushe,newsushe,sizeof(stud[i].sushe));
stud[i].sushe[sizeof(stud[i].sushe)-1]='\0'; printf("请输入新电话号码:");
scanf("%s",newtel);
strncpy(stud[i].tel,newtel,sizeof(stud[i].tel));
stud[i].tel[sizeof(stud[i].tel)-1]='\0'; printf("请输入新qq号码:");
scanf("%s",newname);
strncpy(stud[i].qq,newqq,sizeof(stud[i].qq));
stud[i].qq[sizeof(stud[i].qq)-1]='\0'; printf("请输入新电子邮箱:");
scanf("%s",newemail);
strncpy(stud[i].email,newemail,sizeof(stud[i].email));
stud[i].email[sizeof(stud[i].email)-1]='\0'; printf("\t\t\t修改信息成功咯\n"); /*返回成功信息*/
return (n);
}
void main() /*主函数*/
{
int n=0;
system("color 1A"); //调用dos改背景与前景色
for(;;)
{
switch(menu_select()) /*选择判断*/
{
case 1:
printf("\t\t\t输入信息\n"); /*输入若干条记录*/
n=Input(stu,n);
break;
case 2:
printf("\t\t\t显示信息\n"); /*显示所有记录*/
Display(stu,n);
break;
case 3:
printf("\t\t\t按学号排序\n");
Sort_by_num(stu,n); /*按学号排序*/
printf("\t\t\t排列成功咯!\n");
printf("\t\t\t");
system("pause");
break;
case 4:
printf("\t\t\t修改学生信息\n");
n=Modify_a_record(stu,n); /*按姓名查找,修改一条记录*/
printf("\t\t\t");
system("pause");
break;
case 5:
printf("\t\t\t删除学生信息\n");
n=Delete_a_record(stu,n); /*按姓名查找,删除一条记录*/
printf("\t\t\t");
system("pause");
break;
case 6:
printf("\t\t\t查找一个信息\n");
Query_a_record(stu,n); /*查找并显示一个记录*/
printf("\t\t\t");
system("pause");
break;
case 7:
printf("\t\t\t打开保存过的文件\n");
n=AddfromText(stu,n); /*新增功能,输出统计信息*/
break;
case 8:
printf("\t\t\t保存数据到文件\n");
WritetoText(stu,n); /*循环写入数据*/
printf("\t\t\t");
system("pause");
break;
case 0:
printf("\t\t\t感谢使用,祝你好运哦!\n"); /*结束程序*/
printf("\t\t\t");
system("pause");
exit(0);
}
}
}
⑸ C语言的通讯录代码是什么
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define N 100 void input();//添加新用户函数
void amend();//修改用户信息函数
void delete_client();//删除用户信息函数
void demand_client();//用户信息查询函数
void collect_telephone();//用户信息汇总函数
void save_client(struct telephone message);//保存函数
void demand_name();//按用户名查询
void demand_telephone();//按电话号码查询
struct telephone
{
char client_name[20];
char client_address[30];
char client_telephone[15];
}; //添加新用户函数
void input()
{
struct telephone message;
char reply='y';
char save='y';
while (reply=='y')
{ printf("用户姓名:");
scanf("%s",message.client_name);
printf("电话号码:");
scanf("%s",message.client_telephone); save_client(message);
printf("要继续吗?(y/n):");
scanf(" %c",&reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //保存函数
void save_client(struct telephone message)
{
FILE *fp;
fp=fopen("message.dat","a+");
if (fp!=NULL)
{
fwrite(&message,sizeof(struct telephone),1,fp);
}
else
{
printf("\n打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
} //修改用户信息函数
void amend()
{
struct telephone message;
FILE *fp;
char amend_name[20];
char reply='y';
char found='y';
char save='y';
int size=sizeof(struct telephone);
while (reply=='y')
{
found='n';
fp=fopen("message.dat","r+w");
if (fp!=NULL)
{
system("cls");
printf("\n请输入要修改的姓名:");
scanf("%s",amend_name);
while ((fread(&message,size,1,fp))==1)
{
if ((strcmp(amend_name,message.client_name))==0)
{
found='y';
break;
}
}
if (found=='y')
{ printf("==========================================\n");
printf("\n用户姓名:%s\n",message.client_name);
printf("\n电话号码:%s\n",message.client_telephone);
printf("==========================================\n");
printf("修改用户信息:\n");
printf("\n用户姓名:");
scanf("%s",message.client_name); printf("\n电话号码:");
scanf("%s",message.client_telephone);
printf("\n要保存吗?(y/n):");
scanf(" %c",&save);
if (save=='y')
{
fseek(fp,-size,1);
fwrite(&message,sizeof(struct telephone),1,fp);
}
}
else
{
printf("无此人信息!\n");
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("要继续吗?(y/n):");
scanf(" %c",&reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //删除用户信息函数
void delete_client()
{
struct telephone message[N];
struct telephone temp_str;
struct telephone delete_str;
int i=0,j=0;
char reply='y';
char found='y';
char confirm='y';
char delete_name[20];
FILE *fp;
while (reply=='y')
{
system("cls");
fp=fopen("message.dat","r");
if (fp!=NULL)
{
i=0;
found='n';
printf("\n请输入姓名:");
scanf("%s",delete_name);
while ((fread(&temp_str,sizeof(struct telephone),1,fp))==1)
{
if ((strcmp(delete_name,temp_str.client_name))==0)
{
found='y';
delete_str=temp_str;
}//查找要删除的记录
else
{
message[i]=temp_str;
i++;
}//将其它无关记录保存起来
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
if (found=='y')
{
printf("==========================================\n");
printf("用户姓名:%s\n",delete_str.client_name);
printf("电话号码:%s\n",delete_str.client_telephone);
printf("==========================================\n");
}
else
{
printf("无此人信息,按任意键返回……\n");
getchar();
break;
}
printf("确定要删除吗?(y/n):");
scanf(" %c",&confirm);
if (confirm=='y')
{
fp=fopen("message.dat","w");
if (fp!=NULL)
{
for(j=0;j<i;j++)
{
fwrite(&message[j],sizeof(struct telephone),1,fp);
}
printf("记录已删除!!!\n");
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
}
printf("要继续吗?(y/n):");
scanf(" %c",&reply);
}
printf("按任意键返回主菜单……\n");
getchar();
}
//用户信息查询函数
void demand_client()
{
int choice=1;
while (choice!=3)
{
system("cls");
printf("电话查询菜单\n");
printf(" 1 按联系人姓名查询\n");
printf(" 2 按联系人电话号码查询\n");
printf(" 3 返回主菜单\n");
printf("请选择(1-3):");
scanf("%d%*c",&choice);
if (choice>3)
{
printf("请输入1-6之间的整数\n");
printf("按任意键返回菜单……\n");
getchar();
continue;
}
if (choice==1)
{
demand_name();
}
else if (choice==2)
{
demand_telephone();
}
}
} //按用户名查询
void demand_name()
{
struct telephone message;
FILE *fp;
char amend_name[20];
char reply='y';
char found='y';
while (reply=='y')
{
found='n';
fp=fopen("message.dat","r+w");
if (fp!=NULL)
{
system("cls");
printf("\n请输入姓名:");
scanf("%s",amend_name);
while ((fread(&message,sizeof(struct telephone),1,fp))==1)
{
if ((strcmp(amend_name,message.client_name))==0)
{
found='y';
break;
}
}
if (found=='y')
{ printf("==========================================\n");
printf("用户姓名:%s\n",message.client_name); printf("电话号码:%s\n",message.client_telephone);
printf("==========================================\n");
}
else
{
printf("无此人信息!\n");
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("要继续吗?(y/n):");
scanf(" %c",&reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //按电话号码查询
void demand_telephone()
{
struct telephone message;
FILE *fp;
char telephone[20];
char reply='y';
char found='y';
while (reply=='y')
{
found='n';
fp=fopen("message.dat","r+w");
if (fp!=NULL)
{
system("cls");
printf("\n请输入电话号码:");
scanf("%s",telephone);
while ((fread(&message,sizeof(struct telephone),1,fp))==1)
{
if ((strcmp(telephone,message.client_telephone))==0)
{
found='y';
break;
}
}
if (found=='y')
{ printf("==========================================\n");
printf("用户姓名:%s\n",message.client_name); printf("电话号码:%s\n",message.client_telephone);
printf("==========================================\n");
}
else
{
printf("无此电话号码的有关信息!\n");
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("要继续吗?(y/n):");
scanf(" %c",&reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //用户信息汇总函数
void collect_telephone()
{
struct telephone message;
FILE *fp;
fp=fopen("message.dat","r");
if (fp!=NULL)
{
system("cls");
printf("\n用户姓名\t\t电话号码\n");
while ((fread(&message,sizeof(struct telephone),1,fp))==1)
{
printf("\n%-24s",message.client_name); printf("%-12s\n",message.client_telephone);
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("按任意键返回主菜单……\n");
getch();
} void main()
{
char choice[10]="";
int len=0;
while (choice[0]!='7')
{ printf("\t==========电话本号码查询系统=============\n"); printf("\t\t 1、添加新联系人\n");
printf("\t\t 2、修改联系人信息\n");
printf("\t\t 3、删除联系人信息\n");
printf("\t\t 4、联系人信息查询\n");
printf("\t\t 5、联系人信息汇总\n");
printf("\t\t 7、退出\n");
printf("\t=========================================\n");
printf("请选择(1-7):");
scanf("%s",choice);
len=strlen(choice);
if (len>1)
{
printf("请输入1-6之间的整数\n");
printf("按任意键返回主菜单……\n");
getchar();
getchar();
continue;
} switch (choice[0]) {
case '1':
input();
break;
case '2':
amend();
break;
case '3':
delete_client();
break;
case '4':
demand_client();
break;
case '5':
collect_telephone();
break; default:
break;
}
}
}
⑹ 求C语言程序设计手机通讯录代码,急,
//这个是我教材上的,不知道你要的是不这个
#include<stdio.h>
#include<string.h>
struct friends_list
{
char name[10];
int age;
char telephone[13];
};
int Count=0;
void new_friend(struct friends_list friends[]);
void search_friend(struct friends_list friends[],char *name);
int main(void)
{
int choice;
char name[10];
struct friends_list friends[50];
do
{
printf("通讯录功能选项:1:新建2:查询0:退出\n");
printf("请选择功能:\n");
scanf("%d",&choice);
switch(choice)
{
case 1:new_friend(friends);
break;
case 2:printf("请输入要查找的联系人姓名:");
scanf("%s",name);
search_friend(friends,name);
break;
case 0:break;
}
}
while(choice!=0);
printf("谢谢使用通讯录功能!\n");
return 0;
}
void new_friend(struct friends_list friends[])
{
struct friends_list f;
if(Count==50)
{
printf("通讯录已满!\n");
return;
}
printf("请输入新联系人的姓名:");
scanf("%s",f.name);
printf("请输入新联系人的年龄:");
scanf("%d",&f.age);
printf("请输入新联系人的联系电话:");
scanf("%s",f.telephone);
friends[Count]=f;
Count++;
}
void search_friend(struct friends_list friends[],char *name)
{
int i,flag=0;
if(Count==0)
{
printf("通讯录是空的!\n");
return;
}
for(i=0;i<Count;i++)
if(strcmp(name,friends[i].name)==0)
{
flag=1;
break;
}
if(flag)
{
printf("姓名:%s\t",friends[i].name);
printf("年龄:%d\t",friends[i].age);
printf("电话:%s\n",friends[i].telephone);
}
else
printf("无此联系人!");
}
⑺ c语言手机通讯录 重谢
#include<stdio.h> struct Class { char *cname; //名字 char *cphon; //电话号码 char *cuphon; //单位电话 char *cmphon; //手机号码 char *cqq; //qq号码 char *cbday; //生日日期 struct Class *node; //其余的自己可以加***** }; typedef struct Class Students; //通讯录结构 typedef Students *Ps; Ps TcraseClsSt(Ps lina); // 催的操作Ps CraseClsSt(Ps lina,char *cname,char *cphon,char *cuphon,char *cmphon,char *cqq,char *cbday); //存过程void OutSmary(Ps lina); //输出结果 void main() { Ps lina=NULL; lina=TcraseClsSt(lina); if(lina!=NULL) //如果lina为NULL是错误内存非配失败 { OutSmary(lina); } else printf("Error"); getch(); } Ps TcraseClsSt(Ps lina) { int Cmd=0; char cname[100]; char cphon[100]; char cuphon[100]; char cmphon[100]; char cqq[100]; char cbday[100]; do { printf("Please enter a name:"); scanf("%s",cname); //提示并输入数据 printf("Enter the phone number:"); scanf("%s",cphon); printf("Enter the unit telephone:"); scanf("%s",cuphon); printf("Enter phone number:"); scanf("%s",cmphon); printf("Enter the number qq:"); scanf("%s",cqq); printf("Enter your date of birth:"); scanf("%s",cbday); lina=CraseClsSt(lina,cname,cphon,cuphon,cmphon,cqq,cbday);//把数据存入链表 printf("Enter -1 to exit any exit:"); scanf("%d",&Cmd); } while(Cmd!=-1&&lina!=NULL); return lina; } Ps CraseClsSt(Ps lina,char *cname,char *cphon,char *cuphon,char *cmphon,char *cqq,char *cbday) //链表存入函数 { Ps merory; Ps linb; merory=(Ps)malloc(sizeof(Students)); if(!merory) { return NULL; //merory为NULL是返回零 NULL } merory->node=NULL; strcpy(merory->cname,cname); //用字符创拷贝函数 段错午 在turbo c 编译器可以通过 gcc可以用别的方法处理 strcpy(merory->cphon,cphon); strcpy(merory->cuphon,cuphon); strcpy(merory->cmphon,cmphon); strcpy(merory->cqq,cqq); strcpy(merory->cbday,cbday); if(lina==NULL) return merory; linb=lina; while(linb->node!=NULL) linb=linb->node; linb->node=merory; return lina; } void OutSmary(Ps lina) //链表输出函数 { while(lina!=NULL) { printf("name:%s,Phone:%s,Unit Number:%s,Phone number:%s,qq No:%s,Date of Birth:%s\n", lina->cname,lina->cphon,lina->cuphon,lina->cmphon,lina->cqq,lina->cbday); lina=lina->node; } }