C语言编写一个通讯录管理系统的源代码如下:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/*定义保存通迅录的信息*/
structfriends
{
charname[20]/*名字*/
charprovince[20]/*省份*/
charcity[20]/*所在城市*/
charnation[20]/*民族*/
charsex[2]/*性别M/F*/
intage/*年龄*/
}
扩展资料
1、在C++中应该使用inline内连函数替代宏调用,这样既可达到宏调用的目的,又避免了宏调用的弊端。
2、在C语言两个函数的名称不能相同,否则会导致编译错误。在C++中,函数名相同而参数不同的两个函数被解释为重载。
3、在大型程序中,使函数名易于管理和使用,不必绞尽脑汁地去处理函数名。
#include <cstdio>#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std
cout<<"如果需要此程序的改版,请私信或加我QQ:2416560314"<<endl
FILE *p,*p1
struct note{
char name[100]
char phone[100]
char mail[100]
}people[1000]
int main()
{
int n=0,i,j
p=fopen("list.txt","r")
if(p==NULL)
{
fclose(p)
p=fopen("list.txt","w")
fclose(p)
}
while(1)
{
n=0
p=fopen("list.txt","r")
while(fscanf(p,"%s%s%s",people[n].name,people[n].phone,people[n].mail)!=EOF)
n++
fclose(p)
///---------------
int k
cout<<"输入1读取,输入2输入"<<endl
cin>>k
if(k==1)
{
cout<<"输入信息"<<endl
char s[100]
cin>>s
bool ok=0
for(i=0i<strlen(s)i++)
if(s[i]>='0'&&s[i]<='9')
ok=1
if(ok==0)
{
//cout<<"通过姓名找到联系人"<<endl
//system("pause")
bool you=0
for(i=0i<ni++)
if(strcmp(s,people[i].name)==0)
{
you=1
cout<<"姓名"<<people[i].name<<endl
cout<<"电话号码"<<people[i].phone<<endl
cout<<"邮箱"<<people[i].mail<<endl
}
if(you==0)
cout<<"没有通过姓名找到联系人"<<endl
}
if(ok==1)
{
//cout<<"通过电话找联系人"<<endl
//system("pause")
bool you=0
for(i=0i<ni++)
if(strcmp(s,people[i].phone)==0)
{
you=1
cout<<"姓名"<<people[i].name<<endl
cout<<"电话号码"<<people[i].phone<<endl
cout<<"邮箱"<<people[i].mail<<endl
}
if(you==0)
cout<<"没有通过电话找到联系人"<<endl
}
}
if(k==2)
{
p1=fopen("list.txt","a+")
char ss[1000]
cout<<"请输入姓名"<<endl
cin>>ss
fprintf(p1,"%s\n",ss)
cout<<"请输入电话"<<endl
cin>>ss
fprintf(p1,"%s\n",ss)
cout<<"请输入邮箱"<<endl
cin>>ss
fprintf(p1,"%s\n",ss)
fclose(p1)
}
}
return 0
}
一个通信录管理程序有以下功能: . 插入新的通信记录; . 查找某人的通信记录; . 删除某人的通信记录; . 浏览通信录; . 结束程序运行。 设每条通信录包含以下内容: .姓名 .地址 .邮政编码 .电话号码 并设通信录全部以字符行形式存于文件中,每四个字符行构成一个通信录记录。 程序启动后,自动从指定的文件中读取通信录信息。程序运行结束后,又自动将内存中修改过的通信录 信息保护到文件中。为了查找,插入,删除等操作的方便,程序内部以双向链表形式组织通信录信息。设启 动程序的命令行可带通信录文件参数。如启动时未给出文件名参数,则程序首先要求用户键入通信录文件