当前位置:首页 » 编程语言 » c语言电话本

c语言电话本

发布时间: 2023-03-08 07:56:35

1. c语言设计个人通讯录管理系统

1、创建学生社团管理系统的欢迎界面,该欢迎界面以图片的方式呈现,系统启动时再屏幕中居中显示。

2. 用C语言做通讯录

#include"stdio.h"
#include"string.h"
#include"stdlib.h"
struct Telephone
{
char number[200];
char name[20];
char off[20];
char addrass[20];
char mail[20];
char telephone[20];
struct Telephone *next;
};
typedef struct Telephone TEL;
TEL *head=NULL;
void Menu(); /*菜单*/
void Crease(); /*添加条目*/
void print(); /*输出条目*/
void Search(); /*查找条目( 按姓名 )*/
void Delate(); /*删除信息*/
void Save(); /*保存到文件*/
void Open(); /*打开文件*/
void Change(); /*修改信息*/
void Arrange(); /*排序*/
void main()
{
char ch;
Open(); /*打开文件*/
while(1)
{
Menu(); /*显示菜单*/
scanf(" %c",&ch);
switch(ch)
{
case '1':Crease(); /*添加条目*/
break;

case '2':Search(); /*查找条目1.按姓名*/
break;
case '3':Change(); /*修改信息*/
print();
break;
case '4': Delate(); /*删除信息*/
print(); /*输出删除后的结果*/
break;
case '5':print(); /*输出条目*/
break;
case '0':Save(); /*保存并释放内存*/
exit(0); /*退出*/
break;
default:
printf("选择错误!");
break;
}
}
}

/*菜单*/
void Menu()
{
printf("\n*****************通讯录系统*****************\n");
printf("\t1.录入。\n");
printf("\t2.按姓名查询\n");
printf("\t3.修改信息\n");
printf("\t4.删除\n");
printf("\t5.输出\n");
printf("\t0.保存并退出!\n");
printf("*************************************************\n");
printf("\t请选择:");
}

/*添加条目*/
void Crease()
{
TEL *p1=NULL,*p2=NULL;
p1=(TEL *)malloc(sizeof(TEL)); /*申请结点*/
printf("输入编号:");
scanf("%s",p1->number);
printf("输入姓名:"); /*添加信息*/
scanf("%s",p1->name);
printf("输入单位:");
scanf("%s",p1->off);
printf("输入地址:");
scanf("%s",p1->addrass);
printf("输入邮箱:");
scanf("%s",p1->mail);
printf("输入电话:");
scanf("%s",p1->telephone);
p1->next=NULL; /*保存到链表*/

if(head==NULL)
{
head=(TEL *)malloc(sizeof(TEL)); /*申请空间*/
head->next=p1;
}
else
{
for(p2=head;p2->next!=NULL;p2=p2->next); /*找到结点尾*/
p2->next=p1;
}
printf("此信息已添加!");
}

/*输出学生信息*/
void print()
{
TEL *p=NULL;
if(head==NULL)
{
printf("此通讯录中无记录,请输入记录后在使用本功能!\n");
return;
}
printf("**************通讯录系统*********************\n"); /*输出信息*/
printf("编号\t姓名\t单位\t地址\t邮箱\t电话\n");
for(p=head->next;p!=NULL;p=p->next)
printf("%s\t%s\t%s\t%s\t%s\t%s\n",p->number,p->name,p->off,p->addrass,p->mail,p->telephone);
}

/*查找信息1.按姓名*/
void Search()
{
TEL *p;
char findname[20];
printf("请输入要查找的姓名:");
scanf("%s",findname);
printf("**************通讯录系统*********************\n");
printf("编号\t姓名\t单位\t地址\t邮箱\t电话\n");
for(p=head;p!=NULL;p=p->next)
{
if(strcmp(p->name,findname)==0)
printf("%s\t%s\t%s\t%s\t%s\t%s\n",p->number,p->name,p->off,p->addrass,p->mail,p->telephone);

}
}

/*删除信息*/
void Delate()
{
char findname[20]; /*先查找 后删除*/
TEL *p = head, *pr ;
printf("输入要删除的姓名:");
scanf(" %s",findname);
if (head->next == NULL)
{
printf("空链表!\n");
return;
}
while ((strcmp(p->name,findname)!=0 )&& p->next != NULL)
{
pr =p;
p =p->next;
}
if (strcmp(findname, p->name)==0) /*输出删除信息*/
{
printf("%s\t%s\t%s\t%s\t%s\t%s\n",p->number,p->name,p->off,p->addrass,p->mail,p->telephone);
if (p == head->next)
head->next = p->next;
else
pr->next = p->next;
free(p);
printf("此信息已删除!");
}
else printf("无此信息!\n");

}
void Save() /*保存链表信息到文件并释放内存空间*/
{
TEL *p=NULL;
FILE *fp;
char *Book="books.txt";
if(head==NULL)
{
printf("\n记录为空!\n");
return;
}
else
p=head->next;
if((fp=fopen(Book,"wb+"))==NULL)
{
printf("\n打不开文件!\n");
return;
}
while(p!=NULL) /*保存信息*/
{
fwrite(p,sizeof(TEL),1,fp);
p=p->next;
}
printf("保存完毕!\n");
fclose(fp);
/*****释放链表空间*****/
for(;head->next!=NULL;)
{
p=head->next;
head->next=head->next->next;
free(p);
}
free(head);
}
/*文件信息输出到链表*/
void Open()
{
FILE *fp;
TEL *p1=NULL,*p2=NULL,*temp=NULL;
if((fp=fopen("books.txt","rb+"))==NULL)
{
printf("\n****************通讯录******************\n");
return;
}
head=(TEL *)malloc(sizeof(TEL));
head->next=NULL;
temp=p2=head;
while(! feof(fp)) /*循环读取*/
{
p1=(TEL *)malloc(sizeof(TEL));
temp=p2;
p2->next=p1;
p2=p1;
fread(p1,sizeof(TEL),1,fp);
}
temp->next=NULL;
fclose(fp); /*关闭文件*/
}
void Change()
{
TEL *p;
char name[20];
printf("输入要修改人的姓名:");
scanf("%s",name);

for(p=head->next;p!=NULL;p=p->next)
{
if(strcmp(p->name,name)==0)
{printf("**************通讯录系统*********************\n");
printf("编号\t姓名\t单位\t地址\t邮箱\t电话\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\n",p->number,p->name,p->off,p->addrass,p->mail,p->telephone);
printf("输入要修改的内容:\n");
printf("输入编号:");
scanf("%s",p->number);
printf("输入姓名:");
scanf("%s",p->name);
printf("输入单位:");
scanf("%s",p->off);
printf("输入地址:");
scanf("%s",p->addrass);
printf("输入邮箱:");
scanf("%s",p->mail);
printf("输入电话:");
scanf("%s",p->telephone);
}
else printf("无此信息!\n");
}
}

自己对比一下

3. 用c语言编写通讯录

自己写的,看一下

// 头文件部分

//============================
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>

#include <conio.h>

// 初始化数据部分
int Menu();
void Start();
void Write();
void Read();
void Search();
void Detele();
void beauty();
void Rework();
void Lock();
int Judge();
//============================
struct Student{
char name[20];
char Tel[20];
char QQ[20];
int age;
}xy[100];
char wenjian[10000];
char Number[10];
char number=0;
int GOTO;
//
int main()
{
Start();
for(;;)
{
GOTO=Menu();
if(GOTO==1)
{
for(;;)
{
Write();
int judge=Judge();
if(judge==2)
{
break;
}
}
}
if(GOTO==2)
{
for(;;)
{
Read();
system("pause");
break;
}
}
if(GOTO==3)
{
for(;;)
{
Search();
int judge=Judge();
if(judge==2)
{
break;
}
}
}
if(GOTO==4)
{
for(;;)
{
Rework();
int judge=Judge();
if(judge==2)
{
break;
}
}
}
if(GOTO==5)
{
Detele();
break;
}
if(GOTO==6)
{
beauty();
break;
}
if(GOTO==7)
{
}
if(GOTO==8)
{
printf("");
break;
}
if(GOTO==9)
{
printf("\t\t\t退出系统\n\n");
return 0;
}
if(GOTO==0)
{
printf("");
break;
}
}
// beauty();
//
// Write();
// Read();
// Search();
// Rework();
// Detele();
return 0;
}

void Write()
{
printf("\t\t\t请输入好友名字\n");
scanf("%s",&xy[number].name);
printf("\t\t\t请输入好友电话号码\n");
scanf("%s",&xy[number].Tel);
printf("\t\t\t请输入好友QQ号码\n");
scanf("%s",&xy[number].QQ);
printf("\t\t\t请输入好友年龄\n");
scanf("%d",&xy[number].age);

FILE *file;
if((file=fopen("Friend.txt","rt"))==NULL)
{
file=fopen("Friend.txt","wt");
fprintf(file,"%-20s%-20s%-20s%-20s","姓名","电话","QQ","年龄");
}
file=fopen("Friend.txt","at");
fprintf(file,"%-20s%-20s%-20s%-20d\n",xy[number].name,xy[number].Tel,xy[number].QQ,xy[number].age);
fclose(file);
number++;
Number[0]=number;
FILE * Sta;
if((Sta=fopen("number.txt","r"))=NULL)
{
Sta=fopen("number.txt","wt");
exit(1);
}
Sta=fopen("number.txt","wt");
fprintf(Sta,"%d",Number[0]);

fclose(Sta);
}

void Read()
{
printf("\t\t\t您通讯录中一共有%d位好友\n",Number[0]);

FILE* read;
if((read=fopen("Friend.txt","r"))=NULL)
{
printf("\t\t\t您通讯中当前没有好友,请返回添加\n");
}
read=fopen("Friend.txt","rt");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
for(int i=0;i<number;i++)
{

fscanf(read,"%s%s%s%d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,&xy[i].age);

printf("%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);

}
/* fread(wenjian,10000,1,read);
for(int i=0;i<number*80+80;i++)
{
printf("%c",wenjian[i]);

}
printf("\n");
*/

fclose(read);
}

void beauty()
{

int d;
do{
printf("choose");
scanf("%d",&d);
}while(d<1&&d>5);
if(d==1)
{
system("color 27");
printf("===1===");

}
if(d==2)
{
system("color 37");
printf("===2===");
}
if(d==3)
{
system("color 47");
printf("===3===");
}
if(d==4)
{
system("color 57");
printf("===4===");
}
if(d==5)
{
system("color 67");
printf("===5===");
}

}
void Start()
{
FILE* Start;
if((Start=fopen("number.txt","r"))==NULL)
{
Start=fopen("number.txt","w");
number=0;
Number[0]=number;
fscanf(Start,"%d",&Number[0]);
printf("\t\t\t您的通讯录中还没有任何好友,赶快添加吧.此次操作需要重新运行程序。\n");
exit(1);
}
Start=fopen("number.txt","r");
fscanf(Start,"%d",&Number[0]);

number=Number[0];

fclose(Start);

}

void Search()
{
int change=0;
char Searchname[20];
printf("\t\t\t输入要查找的好友的名字\n\n");
scanf("%s",&Searchname);
fflush(stdin);
printf("\t\t\t您要查找的好友是 %s \n\n",Searchname);

FILE *Search;
Search=fopen("Friend.txt","rt");

for(int i=0;i<=number;i++)
{

fscanf(Search,"%s%s%s%d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,&xy[i].age);

if(strcmp(xy[i].name,Searchname)==0)
{
printf("\t\t\t下面是该好友的信息:\n\n");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
printf("%-20s%-20s%-20s%-20d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,xy[i].age);
change=1;
}

fclose(Search);
}
if(change==0)
{
printf("\t\t\t您要查找的好友不存在,请返回菜单添加。\n");
}
}

void Rework()
{
char Rework[20];
printf("\t\t\t输入要修改的好友的名字\n\n");
scanf("%s",&Rework);

printf("\t\t\t您要修改 %s 的信息\n\n",Rework);
int Change=0;
FILE *Search;
Search=fopen("Friend.txt","rt");

for(int i=0;i<=number;i++)
{

fscanf(Search,"%s%s%s%d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,&xy[i].age);

if(strcmp(xy[i].name,Rework)==0)
{
printf("\t\t\t下面是该好友的信息:\n\n");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
Change=1;
int Choose;
printf("%-20s%-20s%-20s%-20d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,xy[i].age);
//---------------------------------------------------------------------
do
{
printf("\t\t\tchoose\t\t\t1-----3");

scanf("%d",&Choose);
}while(Choose>3||Choose<1);
if(Choose==1){

printf("\t\t\t请输入好友电话号码\n");
scanf("%s",&xy[i].Tel);
}
if(Choose==2)
{
printf("\t\t\t请输入好友QQ号码\n");
scanf("%s",&xy[i].QQ);
}
if(Choose==3)
{
printf("\t\t\t请输入好友年龄\n");
scanf("%d",&xy[i].age);
}

Search=fopen("Friend.txt","wt");
for(int sta=0;sta<i;sta++)
{
fprintf(Search,"%-20s%-20s%-20s%-20d\n",xy[sta].name,xy[sta].Tel,xy[sta].QQ,xy[sta].age);
}
if(sta==i)
{
fprintf(Search,"%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);
i++;
}
for(i;i<=number;i++)
{
fprintf(Search,"%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);
}
printf("\t\t\t修改后的信息为:\n\n");
Read();

}

fclose(Search);
}
if(Change==0)
{
printf("\t\t\t您要查找的好友不存在,请返回菜单添加。\n");
}
}
void Detele()
{

int change=0;
char delete_friend[20];
printf("\t\t\t输入要删除的好友的名字\n\n");
scanf("%s",&delete_friend);
fflush(stdin);
printf("\t\t\t您要删除的好友是 %s \n\n",delete_friend);

FILE *DeleteF;
DeleteF=fopen("Friend.txt","rt");

for(int i=0;i<=number;i++)
{

fscanf(DeleteF,"%s%s%s%d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,&xy[i].age);

if(strcmp(xy[i].name,delete_friend)==0)
{
printf("\t\t\t下面是该好友的信息:\n\n");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
printf("%-20s%-20s%-20s%-20d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,xy[i].age);
change=1;

DeleteF=fopen("Friend.txt","wt");
for(int st=0;st<i;st++)
{
fprintf(DeleteF,"%-20s%-20s%-20s%-20d\n",xy[st].name,xy[st].Tel,xy[st].QQ,xy[st].age);

}
i++;
for(i;i<=number;i++)
{
printf("%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);
fprintf(DeleteF,"%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);
}
}
//--------------------------------------------------------------------------------

if(change==1)
{
printf("\t\t\t删除后的通讯录信息为:\n\n");

number--;
Number[0]=number;
FILE * St;
if((St=fopen("number.txt","r"))=NULL)
{
St=fopen("number.txt","wt");
exit(1);
}
St=fopen("number.txt","wt");
fprintf(St,"%d",Number[0]);

fclose(St);

fclose(DeleteF);
Start();
Read();
}
}

if(change==0)
{
printf("\t\t\t您要删除的好友不存在。\n");
}

}

void Lock()
{

}

int Menu()
{
printf("\t\t*****欢迎进入通讯管理界面*****\n\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("\t\t\t7.设置管理密码\n");
printf("\t\t\t8.使用注意事项\n");
printf("\t\t\t9.退出通讯系统\n");
printf("\t\t\t0.作者想说的话\n");
printf("\t\t******************************\n\n");

do{
printf("\t\t\t请输入你的选择:\n\n");
scanf("%d",&GOTO);
}while(GOTO>9||GOTO<1);
return GOTO;
}

int Judge()
{
char JUDGE;
do
{
printf("\t\t\t是否继续当前操作\n\n Y(yes) / N(no)\n");
printf("\t\t\t输入你的选择\n");
JUDGE=getch();
if(JUDGE=='y'||JUDGE=='Y')
{
return 1;
}
if(JUDGE=='n'||JUDGE=='N')
{
return 2;
}
}while(JUDGE!='y'||JUDGE!='n');

}

4. c语言程序设计实例

// 电话本Dlg.cpp : 实现文件
//

#include stdafx.h
#include 电话本.h
#include 电话本Dlg.h

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// C电话本Dlg 对话框

C电话本Dlg::C电话本Dlg(CWnd* pParent /*=NULL*/)
: CDialog(C电话本Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);
}

void C电话本Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(C电话本Dlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_EN_CHANGE(IDC_EDIT1, C电话本Dlg::OnName)
ON_EN_CHANGE(IDC_EDIT2, C电话本Dlg::OnPhoto)
ON_EN_CHANGE(IDC_EDIT3, C电话本Dlg::OnAddress)
ON_EN_CHANGE(IDC_EDIT4, C电话本Dlg::OnShow)
ON_BN_CLICKED(IDC_BUTTON1, C电话本Dlg::OnFill)
ON_BN_CLICKED(IDC_BUTTON2, C电话本Dlg::OnInsert)
ON_BN_CLICKED(IDC_BUTTON3, C电话本Dlg::OnFind)
ON_BN_CLICKED(IDC_BUTTON4, C电话本Dlg::OnDelete)
ON_BN_CLICKED(IDC_BUTTON5, C电话本Dlg::OnEdit)
ON_BN_CLICKED(IDC_BUTTON7, C电话本Dlg::OnSave)
END_MESSAGE_MAP()

// C电话本Dlg 消息处理程序

BOOL C电话本Dlg::OnInitDialog()
{
CDialog::OnInitDialog();

// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标

// TODO: 在此添加额外的初始化代码
ifstream InFile(Wab.fsd,ios::in);
listWabList::iterator ItWab;
char Tmp1[8],Tmp2[16],Tmp3[32];
Wab.clear();
while(InFile Tmp1 Tmp2 Tmp3)
{
OutWab.Name=Tmp1;
OutWab.Photo=Tmp2;
OutWab.Address=Tmp3;
Wab.push_front(OutWab);
}
C电话本Dlg::OnFill();

return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}

// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。

void C电话本Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文

SendMessage(WM_ICONERASEBKGND, reinterpret_castWPARAM(dc.GetSafeHdc()), 0);

// 使图标在工作矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(rect);
int x = (rect.Width() - cxIcon 1) / 2;
int y = (rect.Height() - cyIcon 1) / 2;

// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

//当用户拖动最小化窗口时系统调用此函数取得光标显示。
//
HCURSOR C电话本Dlg::OnQueryDragIcon()
{
return static_castHCURSOR(m_hIcon);
}

void C电话本Dlg::OnName()
{
CEdit *pMaxLen=(CEdit*)GetDlgItem(IDC_EDIT1);
pMaxLen-SetLimitText(6);
GetDlgItemText(IDC_EDIT1,InWab.Name);
}

void C电话本Dlg::OnPhoto()
{
CEdit *pMaxLen=(CEdit*)GetDlgItem(IDC_EDIT2);
pMaxLen-SetLimitText(11);
GetDlgItemText(IDC_EDIT2,InWab.Photo);
}

void C电话本Dlg::OnAddress()
{
CEdit *pMaxLen=(CEdit*)GetDlgItem(IDC_EDIT3);
pMaxLen-SetLimitText(30);
GetDlgItemText(IDC_EDIT3,InWab.Address);
}

void C电话本Dlg::OnShow()
{
// TODO: 如果该控件是 RICHEDIT 控件,则它将不会
// 发送该通知,除非重写 CDialog::OnInitDialog()
// 函数并调用 CRichEditCtrl().SetEventMask(),
// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

// TODO: 在此添加控件通知处理程序代码
}

void C电话本Dlg::OnFill()
{
CString OutAll,OutTemp,Space,Enter;
Space=_T( );
Enter=_T(\r\n);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
OutWab=*ItWab;
OutTemp=OutWab.Name Space OutWab.Photo Space OutWab.Address;
OutAll=OutAll OutTemp Enter;
}
SetDlgItemText(IDC_EDIT4,OutAll);
}

void C电话本Dlg::OnInsert()
{
Wab.push_front(InWab);
C电话本Dlg::OnFill();
}

void C电话本Dlg::OnFind()
{
CString OutAll,OutTemp,Space,Enter;
Space=_T( );
Enter=_T(\r\n);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
if(ItWab-Name==InWab.Name)
{
OutTemp=ItWab-Name Space ItWab-Photo Space ItWab-Address;
OutAll=OutAll OutTemp Enter;
}
}
SetDlgItemText(IDC_EDIT4,OutAll);
}

void C电话本Dlg::OnDelete()
{
CString OutAll,OutTemp,Space,Enter;
Space=_T( );
Enter=_T(\r\n);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
if(ItWab-Name==InWab.Name)
{
OutTemp=ItWab-Name Space ItWab-Photo Space ItWab-Address;
OutAll=OutAll OutTemp Enter;
break;
}
}
SetDlgItemText(IDC_EDIT4,OutAll);
if(ItWab!=Wab.end()) Wab.erase(ItWab);
}

void C电话本Dlg::OnEdit()
{
CString OutAll,OutTemp,Space,Enter;
Space=_T( );
Enter=_T(\r\n);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
if(ItWab-Name==InWab.Name)
{
OutTemp=ItWab-Name Space ItWab-Photo Space ItWab-Address;
OutAll=OutAll OutTemp Enter;
break;
}
}
SetDlgItemText(IDC_EDIT4,OutAll);
if(ItWab!=Wab.end())
{
Wab.erase(ItWab);
Wab.push_front(InWab);
}
}

void C电话本Dlg::OnSave()
{
CString Tmp1,Tmp2,Tmp3;
ofstream OutFile(Wab.fsd,ios::out);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
Tmp1=ItWab-Name;
Tmp2=ItWab-Photo;
Tmp3=ItWab-Address;
OutFile Tmp1 ' ' Tmp2 ' ' Tmp3 endl;
}
}
只是个用C语言编写的电话本程序 很有实用意义

5. C语言的通讯录代码是什么

#include x0dx0a#include x0dx0a#include x0dx0a#include x0dx0a#define N 100 void input();//添加新用户函数 x0dx0avoid amend();//修改用户信息函数 x0dx0avoid delete_client();//删除用户信息函数 x0dx0avoid demand_client();//用户信息查询函数 x0dx0avoid collect_telephone();//用户信息汇总函数 x0dx0avoid save_client(struct telephone message);//保存函数 x0dx0avoid demand_name();//按用户名查询 x0dx0avoid demand_telephone();//按电话号码查询 x0dx0a x0dx0astruct telephone x0dx0a{ x0dx0achar client_name[20]; x0dx0achar client_address[30]; x0dx0achar client_telephone[15]; x0dx0a}; //添加新用户函数 x0dx0avoid input() x0dx0a{ x0dx0astruct telephone message; x0dx0achar reply='y' x0dx0achar save='y' x0dx0awhile (reply=='y') x0dx0a{ printf("用户姓名:"); x0dx0ascanf("%s",message.client_name); x0dx0a x0dx0aprintf("电话号码:"); x0dx0ascanf("%s",message.client_telephone); save_client(message); x0dx0a x0dx0aprintf("要继续吗?(y/n):"); x0dx0ascanf(" %c",&reply); x0dx0a} x0dx0aprintf("按任意键返回主菜单??\n"); x0dx0agetchar(); x0dx0agetchar(); x0dx0a} //保存函数 x0dx0avoid save_client(struct telephone message) x0dx0a{ x0dx0aFILE *fp; x0dx0afp=fopen("message.dat","a+"); x0dx0aif (fp!=NULL) x0dx0a{ x0dx0afwrite(&message,sizeof(struct telephone),1,fp); x0dx0a} x0dx0aelse x0dx0a{ x0dx0aprintf("\n打开文件时出现错误,按任意键返回??\n"); x0dx0agetchar(); x0dx0areturn; x0dx0a} x0dx0afclose(fp); x0dx0a} //修改用户信息函数 x0dx0avoid amend() x0dx0a{ x0dx0astruct telephone message; x0dx0aFILE *fp; x0dx0achar amend_name[20]; x0dx0achar reply='y' x0dx0achar found='y' x0dx0achar save='y' x0dx0aint size=sizeof(struct telephone); x0dx0awhile (reply=='y') x0dx0a{ x0dx0afound='n' x0dx0afp=fopen("message.dat","r+w"); x0dx0aif (fp!=NULL) x0dx0a{ x0dx0asystem("cls"); x0dx0aprintf("\n请输入要修改的姓名:"); x0dx0ascanf("%s",amend_name); x0dx0awhile ((fread(&message,size,1,fp))==1) x0dx0a{ x0dx0aif ((strcmp(amend_name,message.client_name))==0) x0dx0a{ x0dx0afound='y' x0dx0abreak; x0dx0a} x0dx0a} x0dx0aif (found=='y') x0dx0a{ printf("==========================================\n"); x0dx0aprintf("\n用户姓名:%s\n",message.client_name); x0dx0a x0dx0aprintf("\n电话号码:%s\n",message.client_telephone); x0dx0aprintf("==========================================\n"); x0dx0aprintf("修改用户信息:\n"); x0dx0aprintf("\n用户姓名:"); x0dx0ascanf("%s",message.client_name); printf("\n电话号码:"); x0dx0ascanf("%s",message.client_telephone); x0dx0aprintf("\n要保存吗?(y/n):"); x0dx0ascanf(" %c",&save); x0dx0aif (save=='y') x0dx0a{ x0dx0afseek(fp,-size,1); x0dx0afwrite(&message,sizeof(struct telephone),1,fp); x0dx0a} x0dx0a} x0dx0aelse x0dx0a{ x0dx0aprintf("无此人信息!\n"); x0dx0a} x0dx0a} x0dx0aelse x0dx0a{ x0dx0aprintf("打开文件时出现错误,按任意键返回??\n"); x0dx0agetchar(); x0dx0areturn; x0dx0a} x0dx0afclose(fp); x0dx0aprintf("要继续吗?(y/n):"); x0dx0ascanf(" %c",&reply); x0dx0a} x0dx0aprintf("按任意键返回主菜单??\n"); x0dx0agetchar(); x0dx0agetchar(); x0dx0a} //删除用户信息函数 x0dx0avoid delete_client() x0dx0a{ x0dx0astruct telephone message[N]; x0dx0astruct telephone temp_str; x0dx0astruct telephone delete_str; x0dx0aint i=0,j=0; x0dx0achar reply='y' x0dx0achar found='y' x0dx0achar confirm='y' x0dx0achar delete_name[20]; x0dx0aFILE *fp; x0dx0awhile (reply=='y') x0dx0a{ x0dx0asystem("cls"); x0dx0afp=fopen("message.dat","r"); x0dx0aif (fp!=NULL) x0dx0a{ x0dx0ai=0; x0dx0afound='n' x0dx0aprintf("\n请输入姓名:"); x0dx0ascanf("%s",delete_name); x0dx0awhile ((fread(&temp_str,sizeof(struct telephone),1,fp))==1) x0dx0a{ x0dx0aif ((strcmp(delete_name,temp_str.client_name))==0) x0dx0a{ x0dx0afound='y' x0dx0adelete_str=temp_str; x0dx0a}//查找要删除的记录 x0dx0aelse x0dx0a{ x0dx0amessage[i]=temp_str; x0dx0ai++; x0dx0a}//将其它无关记录保存起来 x0dx0a} x0dx0a} x0dx0aelse x0dx0a{ x0dx0aprintf("打开文件时出现错误,按任意键返回??\n"); x0dx0agetchar(); x0dx0areturn; x0dx0a} x0dx0afclose(fp); x0dx0aif (found=='y') x0dx0a{ x0dx0aprintf("==========================================\n"); x0dx0aprintf("用户姓名:%s\n",delete_str.client_name); x0dx0a x0dx0aprintf("电话号码:%s\n",delete_str.client_telephone); x0dx0aprintf("==========================================\n"); x0dx0a} x0dx0aelse x0dx0a{ x0dx0aprintf("无此人信息,按任意键返回??\n"); x0dx0agetchar(); x0dx0abreak; x0dx0a} x0dx0aprintf("确定要删除吗?(y/n):"); x0dx0ascanf(" %c",&confirm); x0dx0aif (confirm=='y') x0dx0a{ x0dx0afp=fopen("message.dat","w"); x0dx0aif (fp!=NULL) x0dx0a{ x0dx0afor(j=0;j3) x0dx0a{ x0dx0aprintf("请输入1-6之间的整数\n"); x0dx0aprintf("按任意键返回菜单??\n"); x0dx0a getchar(); x0dx0acontinue; x0dx0a} x0dx0aif (choice==1) x0dx0a{ x0dx0ademand_name(); x0dx0a} x0dx0aelse if (choice==2) x0dx0a{ x0dx0ademand_telephone(); x0dx0a} x0dx0a} x0dx0a} //按用户名查询 x0dx0avoid demand_name() x0dx0a{ x0dx0astruct telephone message; x0dx0aFILE *fp; x0dx0achar amend_name[20]; x0dx0achar reply='y' x0dx0achar found='y' x0dx0awhile (reply=='y') x0dx0a{ x0dx0afound='n' x0dx0afp=fopen("message.dat","r+w"); x0dx0aif (fp!=NULL) x0dx0a{ x0dx0asystem("cls"); x0dx0aprintf("\n请输入姓名:"); x0dx0ascanf("%s",amend_name); x0dx0awhile ((fread(&message,sizeof(struct telephone),1,fp))==1) x0dx0a{ x0dx0aif ((strcmp(amend_name,message.client_name))==0) x0dx0a{ x0dx0afound='y' x0dx0abreak; x0dx0a} x0dx0a} x0dx0aif (found=='y') x0dx0a{ printf("==========================================\n"); x0dx0aprintf("用户姓名:%s\n",message.client_name); printf("电话号码:%s\n",message.client_telephone); x0dx0aprintf("==========================================\n"); x0dx0a} x0dx0aelse x0dx0a{ x0dx0aprintf("无此人信息!\n"); x0dx0a} x0dx0a} x0dx0aelse x0dx0a{ x0dx0aprintf("打开文件时出现错误,按任意键返回??\n"); x0dx0agetchar(); x0dx0areturn; x0dx0a} x0dx0afclose(fp); x0dx0aprintf("要继续吗?(y/n):"); x0dx0ascanf(" %c",&reply); x0dx0a} x0dx0aprintf("按任意键返回主菜单??\n"); x0dx0agetchar(); x0dx0agetchar(); x0dx0a} //按电话号码查询 x0dx0avoid demand_telephone() x0dx0a{ x0dx0astruct telephone message; x0dx0aFILE *fp; x0dx0achar telephone[20]; x0dx0achar reply='y' x0dx0achar found='y' x0dx0awhile (reply=='y') x0dx0a{ x0dx0afound='n' x0dx0afp=fopen("message.dat","r+w"); x0dx0aif (fp!=NULL) x0dx0a{ x0dx0asystem("cls"); x0dx0aprintf("\n请输入电话号码:"); x0dx0ascanf("%s",telephone); x0dx0awhile ((fread(&message,sizeof(struct telephone),1,fp))==1) x0dx0a{ x0dx0aif ((strcmp(telephone,message.client_telephone))==0) x0dx0a{ x0dx0afound='y' x0dx0abreak; x0dx0a} x0dx0a} x0dx0aif (found=='y') x0dx0a{ printf("==========================================\n"); x0dx0aprintf("用户姓名:%s\n",message.client_name); printf("电话号码:%s\n",message.client_telephone); x0dx0aprintf("==========================================\n"); x0dx0a} x0dx0aelse x0dx0a{ x0dx0aprintf("无此电话号码的有关信息!\n"); x0dx0a} x0dx0a} x0dx0aelse x0dx0a{ x0dx0aprintf("打开文件时出现错误,按任意键返回??\n"); x0dx0agetchar(); x0dx0areturn; x0dx0a} x0dx0afclose(fp); x0dx0aprintf("要继续吗?(y/n):"); x0dx0ascanf(" %c",&reply); x0dx0a} x0dx0aprintf("按任意键返回主菜单??\n"); x0dx0agetchar(); x0dx0agetchar(); x0dx0a} //用户信息汇总函数 x0dx0avoid collect_telephone() x0dx0a{ x0dx0astruct telephone message; x0dx0aFILE *fp; x0dx0afp=fopen("message.dat","r"); x0dx0aif (fp!=NULL) x0dx0a{ x0dx0asystem("cls"); x0dx0aprintf("\n用户姓名\t\t电话号码\n"); x0dx0awhile ((fread(&message,sizeof(struct telephone),1,fp))==1) x0dx0a{ x0dx0aprintf("\n%-24s",message.client_name); printf("%-12s\n",message.client_telephone); x0dx0a} x0dx0a} x0dx0aelse x0dx0a{ x0dx0aprintf("打开文件时出现错误,按任意键返回??\n"); x0dx0agetchar(); x0dx0areturn; x0dx0a} x0dx0afclose(fp); x0dx0aprintf("按任意键返回主菜单??\n"); x0dx0agetch(); x0dx0a} void main() x0dx0a{ x0dx0achar choice[10]=""; x0dx0aint len=0; x0dx0awhile (choice[0]!=ƍ') x0dx0a{ printf("\t==========电话本号码查询系统=============\n"); printf("\t\t 1、添加新联系人\n"); x0dx0aprintf("\t\t 2、修改联系人信息\n"); x0dx0aprintf("\t\t 3、删除联系人信息\n"); x0dx0aprintf("\t\t 4、联系人信息查询\n"); x0dx0aprintf("\t\t 5、联系人信息汇总\n"); x0dx0a x0dx0aprintf("\t\t 7、退出\n"); x0dx0aprintf("\t=========================================\n"); x0dx0aprintf("请选择(1-7):"); x0dx0ascanf("%s",choice); x0dx0alen=strlen(choice); x0dx0aif (len>1) x0dx0a{ x0dx0aprintf("请输入1-6之间的整数\n"); x0dx0aprintf("按任意键返回主菜单??\n"); x0dx0agetchar(); x0dx0agetchar(); x0dx0acontinue; x0dx0a} switch (choice[0]) { x0dx0acase Ƈ': x0dx0ainput(); x0dx0abreak; x0dx0acase ƈ': x0dx0aamend(); x0dx0abreak; x0dx0acase Ɖ': x0dx0adelete_client(); x0dx0abreak; x0d

6. 请大家使用C语言完成电话号码查询系统。 设有一个电话号码薄,它

有虚的,原来的宪法的电话号码的查询的系统有设置一个电话号码和QQ号码不就可以完成了

7. 通讯录代码 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;

}
}
}

热点内容
php计算字符串长度的函数 发布:2024-11-06 23:35:05 浏览:353
小米自制脚本 发布:2024-11-06 23:34:18 浏览:314
qq访问问题 发布:2024-11-06 23:29:20 浏览:648
手机邮件接收服务器怎么设置 发布:2024-11-06 23:23:35 浏览:128
c语言循环例题 发布:2024-11-06 23:05:01 浏览:332
外星人m15r6选哪个配置 发布:2024-11-06 23:03:58 浏览:999
linuxmysql数据库安装 发布:2024-11-06 23:01:28 浏览:117
压缩器能干嘛 发布:2024-11-06 23:01:16 浏览:464
分布式存储算法 发布:2024-11-06 22:55:09 浏览:872
住宅区弱电有哪些强制配置规定 发布:2024-11-06 22:51:22 浏览:827