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
}